WML Variables HowTo

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.
User avatar
zookeeper
WML Wizard
Posts: 9742
Joined: September 11th, 2004, 10:40 pm
Location: Finland

Re: WML Variables HowTo

Post by zookeeper »

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.
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?
I suppose this should work:

Code: Select all

image="$second_unit.profile|~TC($second_unit.side|, magenta)"
The |'s might be unnecessary.
Wussel
Posts: 624
Joined: July 28th, 2012, 5:58 am

Re: WML Variables HowTo

Post by Wussel »

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.

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

UPDATE:
Dugi just said I need kill=no and clear_variable idstore. Would that be everything?
User avatar
zookeeper
WML Wizard
Posts: 9742
Joined: September 11th, 2004, 10:40 pm
Location: Finland

Re: WML Variables HowTo

Post by zookeeper »

Wussel wrote:Dugi just said I need kill=no and clear_variable idstore. Would that be everything?
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.

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
Wussel
Posts: 624
Joined: July 28th, 2012, 5:58 am

Re: WML Variables HowTo

Post by Wussel »

It is working! That was my first macro using variables! Thanks for all the good advice. Now Wesnoth is ready for teamcolored portaits. :lol2:
User avatar
Paulomat4
Moderator Emeritus
Posts: 730
Joined: October 16th, 2012, 3:32 pm
Location: Wesmere library, probably summoning Zhangor

Re: WML Variables HowTo

Post by Paulomat4 »

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.
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
User avatar
pyrophorus
Posts: 533
Joined: December 1st, 2010, 12:54 pm

Re: WML Variables HowTo

Post by pyrophorus »

Hi !
Thanks for your appreciation !

Friendly,
User avatar
pyrophorus
Posts: 533
Joined: December 1st, 2010, 12:54 pm

Re: WML Variables HowTo

Post by pyrophorus »

The thing is now incorporated into the wiki (thanks to Adamant14) here

Have fun,
User avatar
Dugi
Posts: 4961
Joined: July 22nd, 2010, 10:29 am
Location: Carpathian Mountains
Contact:

Re: WML Variables HowTo

Post by Dugi »

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.
User avatar
tekelili
Posts: 1039
Joined: August 19th, 2009, 9:28 pm

Re: WML Variables HowTo

Post by tekelili »

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:

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
I would have learned to use [insert_tag] years ago if there has been a predefined macro like this one :wink:
Be aware English is not my first language and I could have explained bad myself using wrong or just invented words.
World Conquest II
User avatar
pyrophorus
Posts: 533
Joined: December 1st, 2010, 12:54 pm

Re: WML Variables HowTo

Post by pyrophorus »

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...
I too... :lol2:

But (thanks to Adamant14), it already is in the wiki. :D

It's nice to read it helped you in some way. Thanks for the report.

Friendly,
User avatar
Sapient
Inactive Developer
Posts: 4453
Joined: November 26th, 2005, 7:41 am
Contact:

Re: WML Variables HowTo

Post by Sapient »

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.
http://www.wesnoth.org/wiki/User:Sapient... "Looks like your skills saved us again. Uh, well at least, they saved Soarin's apple pie."
User avatar
pyrophorus
Posts: 533
Joined: December 1st, 2010, 12:54 pm

Re: WML Variables HowTo

Post by pyrophorus »

Sapient wrote:I enjoyed reading it.
Thanks !
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.
Could you elaborate ? I'm not sure I understand clearly what you mean here.

Friendly,
Post Reply