enclave's WML Macros questions Thread

The place to post your WML questions and answers.

Moderator: Forum Moderators

Forum rules
  • Please use [code] BBCode tags in your posts for embedding WML snippets.
  • To keep your code readable so that others can easily help you, make sure to indent it following our conventions.
Post Reply
User avatar
Ravana
Forum Moderator
Posts: 3004
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: enclave's WML Macros questions Thread

Post by Ravana »

Are you sure it is removed? Its description just has
The event is copied from this unit's wml description into the scenario. The event is carried along with the unit (it can advance etc) and inserted into every scenario where this unit is first created
It doesnt sound like it would be removed from scenario.
User avatar
tekelili
Posts: 1039
Joined: August 19th, 2009, 9:28 pm

Re: enclave's WML Macros questions Thread

Post by tekelili »

Ravana wrote:Are you sure it is removed? Its description just has
The event is copied from this unit's wml description into the scenario. The event is carried along with the unit (it can advance etc) and inserted into every scenario where this unit is first created
It doesnt sound like it would be removed from scenario.
I was about to edit my post after realize I expect that behavior but never really tested it, sry :oops:

Edit: I was just trying to imagine how [event] inside [unit] could be usefull in a single scenario. My second try: "you have a macro to spawn different enemies that relies in [insert_tag] stored [unit] tags into variables. You suddenly decide introduce an event when some unit is spawned, so write [event] inside [unit] would be straightforward solution."
Be aware English is not my first language and I could have explained bad myself using wrong or just invented words.
World Conquest II
enclave
Posts: 936
Joined: December 15th, 2007, 8:52 am

Re: enclave's WML Macros questions Thread

Post by enclave »

tekelili wrote:
enclave wrote:Thanks Tekelili, so it is mostly for compaigns and not for multiplayer scenarios then?
In general... yes; but not exactly. Its usefullness is defined as event is written every time unit is on scenario and event is removed when unit dies (if no other unit with same event still alive). So in a single multiplayer scenario, theorically could have some use like "when player do X give him a teasure but only if his first recruit is still alive". Sure you can do it from a scenario [event], but could be more clean write event inside player 1st recuit "[unit]".
Thanks Tekelili, will keep it in mind, sounds useful.
PS. will also test if its actually stops working when unit dies :D
enclave
Posts: 936
Joined: December 15th, 2007, 8:52 am

Re: enclave's WML Macros questions Thread

Post by enclave »

Question number #2
Does observer have a team? if so, then what is the team_name?
Question number #3
Can [label] have multiple team_name? for example team_name=1,2 ? If not I guess i could still do it by placing label twice.. quite sure.?
enclave
Posts: 936
Joined: December 15th, 2007, 8:52 am

Re: enclave's WML Macros questions Thread

Post by enclave »

As for question #1 I found my best way to modify ability with:
1) first use [unit] to_variable=x
2) modify ability with {VARIABLE x.abilities. ... }
3) unstore units on map with [unstore_unit] variable=x
Have not complete my code yet, but it seem to work well and this way I feel I am able to code everything I need.. Will report back if any problems..
User avatar
vultraz
Developer
Posts: 960
Joined: February 7th, 2011, 12:51 pm
Location: Dodging Daleks

Re: enclave's WML Macros questions Thread

Post by vultraz »

You can set a unit's abilities directly in their [unit] tag, without going through variable manipulation. For example:

Code: Select all

    [unit]
        side=1
        type=Elvish Fighter
        x,y=1,1
        [modifications]
            [object]
                [effect]
                    apply_to=new_ability
                    [abilities]
                        {ABILITY_HEALS}
                    [/abilities]
                [/effect]
            [/object]
        [/modifications]
    [/unit]
Creator of Shadows of Deception (for 1.12) and co-creator of the Era of Chaos (for 1.12/1.13).
SurvivalXtreme rocks!!!
What happens when you get scared half to death...twice?
enclave
Posts: 936
Joined: December 15th, 2007, 8:52 am

Re: enclave's WML Macros questions Thread

Post by enclave »

vultraz wrote:You can set a unit's abilities directly in their [unit] tag, without going through variable manipulation. For example:
Thanks vultraz, but the reason I need to use alternative ways is because I need to add abilities from array of abilities..
User avatar
tekelili
Posts: 1039
Joined: August 19th, 2009, 9:28 pm

Re: enclave's WML Macros questions Thread

Post by tekelili »

enclave wrote:
vultraz wrote:You can set a unit's abilities directly in their [unit] tag, without going through variable manipulation. For example:
Thanks vultraz, but the reason I need to use alternative ways is because I need to add abilities from array of abilities..
I still think [insert_tag] should solve it, mostly because I deal with lot of stuff stored in arrays in WC II via insert_tag.

If you have your abilities stored in my_awesome_abilities and want give the 3rd one, why you can not do something like this? :?

Code: Select all

    [unit]
        side=1
        type=Elvish Fighter
        x,y=1,1
        [modifications]
            [object]
                [effect]
                    apply_to=new_ability
                    [insert_tag]
                        name=abilities
                        variable=my_awesome_abilities[2]
                  [/insert_tag]
                [/effect]
            [/object]
        [/modifications]
    [/unit]
Be aware English is not my first language and I could have explained bad myself using wrong or just invented words.
World Conquest II
enclave
Posts: 936
Joined: December 15th, 2007, 8:52 am

Re: enclave's WML Macros questions Thread

Post by enclave »

tekelili wrote: If you have your abilities stored in my_awesome_abilities and want give the 3rd one, why you can not do something like this? :?
Tekelili You Are The Best!!! Thank you so much! Your solution worked best for me so far!!!

I started to work my way but I came to a new problem.. I could not find way to add array to an array... I had my ability stored in array like your example "my_awesome_abilities" but I failed to find way to insert it into array of previously stored unit :( (into array "my_awesome_unit.abilities"). If anybody knows the way, please let me know how it could be done?

Now with [insert_tag] my next problem is how to insert 2 abilities? because [unit] most likely will not let me use {FOREACH} or do you think it will let me? Or maybe you have some better way in mind? I will need to split somehow "1,2" (string with coma separated list of ability numbers) and then add all abilities in that list.. Splitting a string my least concern, but adding multiple abilities with [insert_tag]?

Thank you so much Tekelili again, I am 1 step forward now.. but still need help :(
PS. tried FOREACH, didn't work or maybe I need more sleep.. I don't know..
if anyone knows how to add array to an array please let me know..
PPS. would [lua] tag work inside [unit]?
Last edited by enclave on May 23rd, 2015, 8:48 pm, edited 1 time in total.
enclave
Posts: 936
Joined: December 15th, 2007, 8:52 am

Re: enclave's WML Macros questions Thread

Post by enclave »

Do you think this would work?
Spoiler:
PPS. This one worked.. and {FOREACH} now working also..

Code: Select all

[set_variables]
name=NS_recruited_unit.abilities
mode=insert
[insert_tag]
name=value
variable=database.abilities[1]
[/insert_tag]
[/set_variables]
I think would make sense for developers to add new tag or macro for insertion of array into array.. instead of code above..
Thanks Tekelili again, your insert_tag came very handy anyway!

So for anyone who would like to insert ability or traits, or role, or special attacks or anything at all into your units, there is a way like this:
Spoiler:
As for me, now I need to find way to split string "1,6,18,4" into 4 variables.. :)
User avatar
vultraz
Developer
Posts: 960
Joined: February 7th, 2011, 12:51 pm
Location: Dodging Daleks

Re: enclave's WML Macros questions Thread

Post by vultraz »

I don't know for sure if this would work, but there is a [set_variables] mode=append key (see InternalActionsWML#.5Bset_variables.5D).

Code: Select all

[set_variables]
    name=my_array_1
    mode=append
    to_variable=my_array_2
[/set_variables]
Again, I do not know if that would work, I'm just guessing. As for splitting a string into 4 variables, you could either use [set_variables] again:

Code: Select all

[set_variables]
    name=array_of_split_keys
    [split]
        list="1,6,18,4"
        key="value"
        seperator=","
    [/split]
[/set_variables]
Should result in array_of_split_keys[0].value being 1, array_of_split_keys[1].value being 6, etc. Or you could use lua (this is a copy of the split() function used in core wml tags:

Code: Select all

local function split(s)
    return tostring(s):gmatch("[^%s,][^,]*")
end

local list = "1,6,18,4"

for i in split(list) do
    -- this inserts the value into the variable name as well, for distinction. So it would be named "my_split_variable1", "my_split_variable6", etc
    wesnoth.set_variable("my_split_variable" .. i, i)
end
Creator of Shadows of Deception (for 1.12) and co-creator of the Era of Chaos (for 1.12/1.13).
SurvivalXtreme rocks!!!
What happens when you get scared half to death...twice?
User avatar
tekelili
Posts: 1039
Joined: August 19th, 2009, 9:28 pm

Re: enclave's WML Macros questions Thread

Post by tekelili »

enclave wrote:Now with [insert_tag] my next problem is how to insert 2 abilities? because [unit] most likely will not let me use {FOREACH} or do you think it will let me? Or maybe you have some better way in mind? I will need to split somehow "1,2" (string with coma separated list of ability numbers) and then add all abilities in that list.. Splitting a string my least concern, but adding multiple abilities with [insert_tag]?
insert_tag has a magical behavior: if you dont specify an index, then isnsert the whole array

Code: Select all

## this code will write as many [abilities] tags as $my_awsome_abilities.length
[insert_tag]
    name=abilities
    variable=my_awsome_abilities
[/isert_tag]
If you want write several tags after use a FOREACH, do your loop before using [unit] tag, store whatever code you want write in a temporal variable, and insert that temporal variable into [unit] or whereever you want. As general advice, you can store any kind of code into variables, and you can write code from variables wherever varible substitution is supported :eng:
Be aware English is not my first language and I could have explained bad myself using wrong or just invented words.
World Conquest II
enclave
Posts: 936
Joined: December 15th, 2007, 8:52 am

Re: enclave's WML Macros questions Thread

Post by enclave »

vultraz wrote:I don't know for sure if this would work, but there is a [set_variables] mode=append key (see InternalActionsWML#.5Bset_variables.5D).

Code: Select all

[set_variables]
    name=my_array_1
    mode=append
    to_variable=my_array_2
[/set_variables]
Again, I do not know if that would work, I'm just guessing.
I tried just to confirm that unfortunately for me it didn't work, not with append, not with insert, not merge and quite sure I tried replace also.. none of them worked. Would be a nice/neat solution if worked. I was even expecting it to work somehow :) Maybe I did something wrong, I don't know.

So the current best solution to anyone who wants to add array into array (insert array inside another array) would be something like this:
1) Better first create a macro in any of your working macros .cfg(s) like this:
#define ARRAY_TO_ARRAY ARRAY_1 TO_ARRAY_2

Code: Select all

[set_variables]
name={TO_ARRAY_2}
mode=insert
[insert_tag]
name=value
variable={ARRAY_1}
[/insert_tag]
[/set_variables]
#enddef
2) Now anytime you need to add one array to another, just use macro {ARRAY_TO_ARRAY the_array_name_without_dollar_sign_that_you_want_to_insert into_array_name_without_dollar_sign_also}
for example:

Code: Select all

{ARRAY_TO_ARRAY my_ability my_unit.abilities}
ATTENTION: I have not tested if it works, maybe it doesn't.. but it should.. you may try to change "mode=insert" into "mode=replace" or "mode=append" or mode=merge.. depending on what you want to achieve it may change the result somehow. Just guessing.
vultraz wrote: As for splitting a string into 4 variables, you could either use [set_variables] again:

Code: Select all

[set_variables]
    name=array_of_split_keys
    [split]
        list="1,6,18,4"
        key="value"
        seperator=","
    [/split]
[/set_variables]
Should result in array_of_split_keys[0].value being 1, array_of_split_keys[1].value being 6, etc.
Thank you very much vultraz, this one I can confirm, it works flawlessly! You saved me a lot of time.
Now I'm 99% done with my abilities code.
tekelili wrote: insert_tag has a magical behavior: if you dont specify an index, then isnsert the whole array

Code: Select all

## this code will write as many [abilities] tags as $my_awsome_abilities.length
[insert_tag]
    name=abilities
    variable=my_awsome_abilities
[/isert_tag]
If you want write several tags after use a FOREACH, do your loop before using [unit] tag, store whatever code you want write in a temporal variable, and insert that temporal variable into [unit] or whereever you want. As general advice, you can store any kind of code into variables, and you can write code from variables wherever varible substitution is supported
Thanks tekelili that would definitely work! So now anybody who read this thread will know how to add abilities from array of abilities in 2 ways.. depending on what they prefer, or even mix them. Thank you for all your time and help!

New question #3
When I download replay of my mod, from replays.wesnoth.org/1.12/
If the replay was a reload it often has out of sync problem. And the first thing that I can see straight away is that there are no villages on map created by means of {MODIFY_TERRAIN {REPLACEMENT} $structures[$i].x $structures[$i].y} macro (http://www.wesnoth.org/macro-reference.xhtml). When players reload, they play perfectly fine.. villages there.. but replay of reload from server.. is problems. Any ideas? Thank you!
PS. just to remind of question #2
Does observer have a team? if so, then what is the team_name?
enclave
Posts: 936
Joined: December 15th, 2007, 8:52 am

Re: enclave's WML Macros questions Thread

Post by enclave »

Question #4
How could I access array of unit_type?
I would need to use some parameters of some unit from list of all existing units of core.. for my descriptions of units..
is there such an array? Please WML version, not lua (if you know lua way, would be useful also for future reference), I'm not in a mood for advanced coding when there is no need to.. I still dont know what causing some OOS in my mod games.. its upsetting enough.
I basically need something like:
...
message="Orcish Assasin, HP: $wesnoth.unit_type.Orcish_Assasin.hitpoints, Moves: $wesnoth.unit_type.Orcish_Assasin.movement ..."
...
How to do it?

Question #5
in core unit_type Troll Whelp has something like #ifdef ENABLE_TROLL_SHAMAN [advance_to] value=Troll Shaman [/advance_to] #enddef
how do I enable troll whelp to advance to troll shaman? I'm less concerned about this one, but really need to know how to do #4..

Thank you everyone!
User avatar
tamanegi
Posts: 161
Joined: August 25th, 2014, 11:38 am
Location: Japan

Re: enclave's WML Macros questions Thread

Post by tamanegi »

There may not be such an array. Instead, "store_unit_type" tag (or "store_unit_type_ids") will satisfy your demand.

example:

Code: Select all

[store_unit_type]
  type = "Orcish Assassin"
  variable = variable_name
[/store_unit_type]
[message]
  message = _"Orcish Assassin, HP: $variable_name.hitpoints, Moves: $variable_name.movement ..."
[/message]
You can add multiple types in single "store_unit_type" with comma separated list...

For ENABLE_TROLL_SHAMAN, see description about "extra_defines" parameter of campaign tag: http://wiki.wesnoth.org/CampaignWML#The ... ign.5D_tag
You will immediately understand. :D
Discord: @tamanegi
It is true that we cannot be free from bugs, but at least let our bugs not always the same...
A Group in a War: my first campaign, An Independence War: and the sequel
Post Reply