WML Variables HowTo
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.
Re: WML Variables HowTo
If you need to view/edit savefiles often, you'll want to turn off the "compressed saves" option in the advanced preferences. Any saves created after that won't be compressed so you don't need to go through the extra step to get to them.
The |'s might be unnecessary.
I suppose this should work:Wussel wrote: I want to read out the portrait imagepath of $second_unit and add a teamcolor order to it:
image= ((portrait imagepath of $second_unit))~TC($second_unit.side, magenta)
How would the code be?
Code: Select all
image="$second_unit.profile|~TC($second_unit.side|, magenta)"
Re: WML Variables HowTo
Wow, it is working. I did not try without the double dash.
The store thing I still have to figure out.
Inside a message is a speaker. Would speaker.side be defined? Or do I have to do the store speaker than get side? Do I have to unstore or delete stored varables after message display? Sorry just starting variable use. I try to figure out a macro, for any message displaying standard portrait with adding current teamcolor.
Here is my take on a macro. Would that be ok`? Or is something missing? I have so many things seen going wrong so I like to ask first.
UPDATE:
Dugi just said I need kill=no and clear_variable idstore. Would that be everything?
The store thing I still have to figure out.
Inside a message is a speaker. Would speaker.side be defined? Or do I have to do the store speaker than get side? Do I have to unstore or delete stored varables after message display? Sorry just starting variable use. I try to figure out a macro, for any message displaying standard portrait with adding current teamcolor.
Here is my take on a macro. Would that be ok`? Or is something missing? I have so many things seen going wrong so I like to ask first.
Code: Select all
#define TC_MESSAGE ID MESS
[store_unit]
name=idstore
[filter]
id={ID}
[/filter]
[/store_unit]
[message]
speaker={ID}
message= _ "{MESS}"
image="$idstore.profile|~TC($idstore.side|, magenta)"
[/message]
#enddef
Dugi just said I need kill=no and clear_variable idstore. Would that be everything?
Re: WML Variables HowTo
Almost. It's variable= instead of name=, and by using _"{MESS}" you're literally asking for "{MESS}" to be translated which doesn't make sense. Instead, you want to mark the string you pass as the argument to the macro as translatable.Wussel wrote:Dugi just said I need kill=no and clear_variable idstore. Would that be everything?
Code: Select all
#define TC_MESSAGE ID MESS
[store_unit]
variable=idstore
kill=no
[filter]
id={ID}
[/filter]
[/store_unit]
[message]
speaker={ID}
message={MESS}
image="$idstore.profile|~TC($idstore.side|, magenta)"
[/message]
{CLEAR_VARIABLE idstore}
#enddef
Re: WML Variables HowTo
It is working! That was my first macro using variables! Thanks for all the good advice. Now Wesnoth is ready for teamcolored portaits.
- Paulomat4
- Moderator Emeritus
- Posts: 730
- Joined: October 16th, 2012, 3:32 pm
- Location: Wesmere library, probably summoning Zhangor
Re: WML Variables HowTo
hey, just popping in to tell you that the HowTo was quite helpful, and that i appreciate the work you've put into this.
What would be nice though would be an index telling on which page deals with which issue. So i son't have to use the search function to find what interests me.
What would be nice though would be an index telling on which page deals with which issue. So i son't have to use the search function to find what interests me.
Creator of Dawn of Thunder and Global Unitmarkers
"I thought Naga's used semi-automatic crossbows with incendiary thermite arrows . . . my beliefs that this race is awesome are now shattered." - Evil Earl
"I thought Naga's used semi-automatic crossbows with incendiary thermite arrows . . . my beliefs that this race is awesome are now shattered." - Evil Earl
- pyrophorus
- Posts: 533
- Joined: December 1st, 2010, 12:54 pm
Re: WML Variables HowTo
Hi !
Thanks for your appreciation !
Friendly,
Thanks for your appreciation !
Friendly,
HowTos: WML filtering, WML variables
- pyrophorus
- Posts: 533
- Joined: December 1st, 2010, 12:54 pm
Re: WML Variables HowTo
I think that there is actually no clickable link to it, it seems that you can find it only if you're looking for it. Good job anyway.
Re: WML Variables HowTo
Nice work, I finally learned to use [insert_tag]. This should be added to wiki, as imho is far better explained (I were unable to understand [insert_tag] from wiki, wich lacks of usefull examples as your guide has).
As side note, due to be a common task, I would like there was a predefined macro like this:
I would have learned to use [insert_tag] years ago if there has been a predefined macro like this one
As side note, due to be a common task, I would like there was a predefined macro like this:
Code: Select all
#define MENU_FROM_ARRAY ARRAY VAR_MENU VAR_OPTION MESSAGE IMAGE
#shows a menu with ARRAY.VAR_MENU values and store user option
#in VAR_OPTION
{FOREACH {ARRAY} nc}
[set_variables]
name=t_menu.option
mode=append
[value]
message=${ARRAY}[$nc].{VAR_MENU}
[command]
{VARIABLE {VAR_OPTION} ${ARRAY}[$nc].{VAR_MENU}}
[/command]
[/value]
[/set_variables]
{NEXT nc}
{VARIABLE t_menu.caption {MESSAGE}}
{VARIABLE t_menu.image {IMAGE}}
{VARIABLE t_menu.speaker narrator}
[insert_tag]
name=message
variable=t_menu
[/insert_tag]
{CLEAR_VARIABLE t_menu,nc}
#enddef
Be aware English is not my first language and I could have explained bad myself using wrong or just invented words.
World Conquest II
World Conquest II
- pyrophorus
- Posts: 533
- Joined: December 1st, 2010, 12:54 pm
Re: WML Variables HowTo
I too...tekelili wrote:Nice work, I finally learned to use [insert_tag]. This should be added to wiki, as imho is far better explained (I were unable to understand [insert_tag] from wiki...
But (thanks to Adamant14), it already is in the wiki.
It's nice to read it helped you in some way. Thanks for the report.
Friendly,
HowTos: WML filtering, WML variables
Re: WML Variables HowTo
I enjoyed reading it.
The advice for macro use with insert_tag could be better.
For exmple, instead of stripping the containing_tag, you can leave it and just insert it as variable=varname.containing_tag
Also, instead of changing it to x,y=$|x1,$|y1 you should have changed [value] to [literal].
With these two approaches, you can reuse general purpose macros, such as those that ship with the game.
The advice for macro use with insert_tag could be better.
For exmple, instead of stripping the containing_tag, you can leave it and just insert it as variable=varname.containing_tag
Also, instead of changing it to x,y=$|x1,$|y1 you should have changed [value] to [literal].
With these two approaches, you can reuse general purpose macros, such as those that ship with the game.
http://www.wesnoth.org/wiki/User:Sapient... "Looks like your skills saved us again. Uh, well at least, they saved Soarin's apple pie."
- pyrophorus
- Posts: 533
- Joined: December 1st, 2010, 12:54 pm
Re: WML Variables HowTo
Thanks !Sapient wrote:I enjoyed reading it.
Could you elaborate ? I'm not sure I understand clearly what you mean here.Sapient wrote: The advice for macro use with insert_tag could be better.
For exmple, instead of stripping the containing_tag, you can leave it and just insert it as variable=varname.containing_tag
Also, instead of changing it to x,y=$|x1,$|y1 you should have changed [value] to [literal].
With these two approaches, you can reuse general purpose macros, such as those that ship with the game.
Friendly,
HowTos: WML filtering, WML variables