Help understanding whitespace in macro symbol

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
Legend_Rider
Posts: 35
Joined: June 20th, 2018, 4:51 pm

Help understanding whitespace in macro symbol

Post by Legend_Rider »

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.

Code: Select all

#define HTTT_TRACK STAGE
    [story]
        [part]
            show_title=yes
            {HTTT_BIGMAP}
            {STAGE}
        [/part]
    [/story]
#enddef
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! :D
User avatar
Ravana
Forum Moderator
Posts: 2948
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: Help understanding whitespace in macro symbol

Post by Ravana »

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]
User avatar
Legend_Rider
Posts: 35
Joined: June 20th, 2018, 4:51 pm

Re: Help understanding whitespace in macro symbol

Post by Legend_Rider »

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.
User avatar
Legend_Rider
Posts: 35
Joined: June 20th, 2018, 4:51 pm

Re: Help understanding whitespace in macro symbol

Post by Legend_Rider »

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

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
And here's a little method I used to call it.

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]
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.
User avatar
Ravana
Forum Moderator
Posts: 2948
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: Help understanding whitespace in macro symbol

Post by Ravana »

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]
Macro is text replacement. How wesnoth treats it:

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]
Macro parameters are like placeholders which simplify reusing them for different situations. So there is no need for separate macro for giving 100 gold for example
User avatar
Legend_Rider
Posts: 35
Joined: June 20th, 2018, 4:51 pm

Re: Help understanding whitespace in macro symbol

Post by Legend_Rider »

Ravana wrote: January 20th, 2021, 9:41 pm

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]
Macro parameters are like placeholders which simplify reusing them for different situations. So there is no need for separate macro for giving 100 gold for example
:shock: Thank you SOOO much! you're my hero!
Post Reply