Help understanding whitespace in macro symbol
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.
- Legend_Rider
- Posts: 35
- Joined: June 20th, 2018, 4:51 pm
Help understanding whitespace in macro symbol
Hello, I went through the "WML for Complete Beginners Tutorial" And after completing it, I was looking through the HttT utils to get a better understanding on how the JOURNEY macro works.
Inspecting the file in "Heir_To_The_Throne/utils/bigmap.cfg" I found a macro symbol with whitespace in it, which wasn't covered in the "Beginners Guide", stating "Macro Symbols can only include alphanumeric characters and underscores, and should be capitalized throughout."
I searched around to see If I could find any instance of this on "reference WML pages" also searching the forum best I could.
I'll attach the segment for reference along with another question which is tied to it.
How does this call the macro "{STAGE}" from within a not yet defined macro?
I looked to see if "{STAGE}" was a pre-defined macro and it isn't built in , neither is it pre-defined anywhere in HttT (that I could find.), I assume that it has to do with the whitespace somehow but haven't been able to figure it out.
Many thanks in advance for help in understanding this!
Inspecting the file in "Heir_To_The_Throne/utils/bigmap.cfg" I found a macro symbol with whitespace in it, which wasn't covered in the "Beginners Guide", stating "Macro Symbols can only include alphanumeric characters and underscores, and should be capitalized throughout."
I searched around to see If I could find any instance of this on "reference WML pages" also searching the forum best I could.
I'll attach the segment for reference along with another question which is tied to it.
Code: Select all
#define HTTT_TRACK STAGE
[story]
[part]
show_title=yes
{HTTT_BIGMAP}
{STAGE}
[/part]
[/story]
#enddef
I looked to see if "{STAGE}" was a pre-defined macro and it isn't built in , neither is it pre-defined anywhere in HttT (that I could find.), I assume that it has to do with the whitespace somehow but haven't been able to figure it out.
Many thanks in advance for help in understanding this!
Re: Help understanding whitespace in macro symbol
It is called macro parameter. https://wiki.wesnoth.org/PreprocessorRef#.23define
You can call that macro like {HTTT_TRACK show_title=no} and output works like
You can call that macro like {HTTT_TRACK show_title=no} and output works like
Code: Select all
[story]
[part]
show_title=yes
(content of HTTT_BIGMAP)
show_title=no # parameter value
[/part]
[/story]
- Legend_Rider
- Posts: 35
- Joined: June 20th, 2018, 4:51 pm
Re: Help understanding whitespace in macro symbol
Ravana wrote: ↑January 20th, 2021, 7:35 pm It is called macro parameter. https://wiki.wesnoth.org/PreprocessorRef#.23define
You can call that macro like {HTTT_TRACK show_title=no} and output works like
Code: Select all
[story] [part] show_title=yes (content of HTTT_BIGMAP) show_title=no # parameter value [/part] [/story]
Thanks a bundle Ravana!
I always feel so silly, why didn't I think of searching for the Preprocessor reference?!
Now... to delve into understanding parameters and how they work! XD
Edit: I think that your reply will help in searching the reference pages more effectively!
I'll be sure to search for surrounding aspects in the future.
Last edited by Legend_Rider on January 22nd, 2021, 10:42 pm, edited 2 times in total.
- Legend_Rider
- Posts: 35
- Joined: June 20th, 2018, 4:51 pm
Re: Help understanding whitespace in macro symbol
Ok, I looked around, read, and tested things in my own little environment and have yet to figure out how parameters work, when I tried to replicate what has been done in HttT, Wesnoth gives the error message "you called a macro with 1 arguments and there are 0 arguments"
This is exactly how I felt about what HttT does when looking at it, I don't understand what the parameter is accomplishing, seeing as it's never called in any of the scenarios or anywhere that I could find.
I know I'm just misunderstanding what a parameter really is in some way...
So, I think I need some light on the subject
Here's my test environment for it.
My macro
And here's a little method I used to call it.
Now, ofc it returns the error message as stated.
If the parameter is removed entirely however, this works just fine.
note: I left some of the WML out for simplicity.
This is exactly how I felt about what HttT does when looking at it, I don't understand what the parameter is accomplishing, seeing as it's never called in any of the scenarios or anywhere that I could find.
I know I'm just misunderstanding what a parameter really is in some way...
So, I think I need some light on the subject
Here's my test environment for it.
My macro
Code: Select all
#define BIG_MONEY GIVEGOLD
[command]
id=Wealthy
side_for=$side_number
[gold]
amount=+1000
side=$side_number
# when this "parameter" is removed the modification works as intended
# but with this "parameter" it gives the error about arguments
{GIVEGOLD}
[/gold]
[/command]
#enddef
Code: Select all
[set_menu_item]
id=money
description= _ "Give me the money!"
[command]
[message]
side_for=$side_number
speaker=narrator
[option]
message= _ "Receive 1000 gold."
{BIG_MONEY}
[/option]
[/message]
[/command]
[/set_menu_item]
If the parameter is removed entirely however, this works just fine.
note: I left some of the WML out for simplicity.
Re: Help understanding whitespace in macro symbol
Code: Select all
#define BIG_MONEY GIVEGOLD
[command]
id=Wealthy
side_for=$side_number
[gold]
amount={GIVEGOLD} # this is common use of parameter
side=$side_number
[/gold]
[/command]
#enddef
Code: Select all
[set_menu_item]
id=money
description= _ "Give me the money!"
[command]
[message]
side_for=$side_number
speaker=narrator
[option]
message= _ "Receive 1000 gold."
{BIG_MONEY 1000} # specifying amount from this
[/option]
[/message]
[/command]
[/set_menu_item]
Code: Select all
ravana@ravana-think ~/wesnoth/wesnoth-lobby $ cat _main.cfg
#define BIG_MONEY GIVEGOLD
[command]
id=Wealthy
side_for=$side_number
[gold]
amount={GIVEGOLD} # this is common use of parameter
side=$side_number
[/gold]
[/command]
#enddef
[set_menu_item]
id=money
description= _ "Give me the money!"
[command]
[message]
side_for=$side_number
speaker=narrator
[option]
message= _ "Receive 1000 gold."
{BIG_MONEY 1000} # specifying amount from this
[/option]
[/message]
[/command]
[/set_menu_item]
ravana@ravana-think ~/wesnoth/wesnoth-lobby $ wesnoth -p _main.cfg out
Battle for Wesnoth v1.14.5+dev (0122a265c42-Modified)
Started on Wed Jan 20 23:43:50 2021
Automatically found a possible data directory at /home/USER/wesnoth/wesnoth-lobby
added 1 defines.
preprocessing common macros from 'data/core' ...
acquired 1664 'data/core' defines.
preprocessing specified resource: _main.cfg ...
acquired 1665 total defines.
preprocessing finished. Took 25 ticks.
ravana@ravana-think ~/wesnoth/wesnoth-lobby $ cat out/_main.cfg
[set_menu_item]
description=_"Give me the money!"
id="money"
[command]
[message]
side_for="$side_number"
speaker="narrator"
[option]
message=_"Receive 1000 gold."
[command]
id="Wealthy"
side_for="$side_number"
[gold]
amount=1000
side="$side_number"
[/gold]
[/command]
[/option]
[/message]
[/command]
[/set_menu_item]
- Legend_Rider
- Posts: 35
- Joined: June 20th, 2018, 4:51 pm
Re: Help understanding whitespace in macro symbol
Thank you SOOO much! you're my hero!Ravana wrote: ↑January 20th, 2021, 9:41 pmMacro parameters are like placeholders which simplify reusing them for different situations. So there is no need for separate macro for giving 100 gold for exampleCode: Select all
[set_menu_item] id=money description= _ "Give me the money!" [command] [message] side_for=$side_number speaker=narrator [option] message= _ "Receive 1000 gold." {BIG_MONEY 1000} # specifying amount from this [/option] [/message] [/command] [/set_menu_item]