Okay, what's up with the macros

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
malthaussen
Posts: 36
Joined: April 6th, 2024, 11:05 pm

Okay, what's up with the macros

Post by malthaussen »

Yes, I know what a macro is.

I have included some standard macros in my scenario .cfg file.
They are macros used in virtually every scenario supplied with the game.
The Campaigns folder for these games do not define any of these macros (eg, "GOLD" or even "DEFAULT_SCHEDULE"), they only define custom macros used in a given campaign (eg, "Two Brothers" defines exactly one macro in its "macros.cfg" file, while "The South Guard" has several macro config files, but only for assorted campaign-specific macros).

But when I try to check out my scenario (by starting a MP game), it immediately tells me that any macro files are "missing." Why are they "missing" from my scenario, but not from others, when they are defined nowhere in the campaign structure? Presumably, there is some library of commonly-used macros, indeed the wiki lists several of them, many of which are used in the supplied campaigns.

So, why can't the game find them for my scenario? This is frustrating, as macros are used everywhere in examples and the wiki.

-- Mal
"Of two choices, I always take the third."
dwarftough
Posts: 484
Joined: August 4th, 2019, 5:27 pm

Re: Okay, what's up with the macros

Post by dwarftough »

Show the exact errors you get, or maybe post the code that gets you into trouble
Co-founder and current maintainer of IsarFoundation, Afterlife Rated and overall Wesnoth Autohost Project
Developer and maintainer of my fork of World Conquest, Invincibles Conquest II
User avatar
malthaussen
Posts: 36
Joined: April 6th, 2024, 11:05 pm

Re: Okay, what's up with the macros

Post by malthaussen »

You got it.

Here is the Campaign .cfg I've put together with the aid of the wiki:

Code: Select all


#Config file for 3rd Army Campaign
#By EMH, April 2024

[textdomain]
	name="wesnoth-3rd_Army"
	path="data/add-ons/3rd_Army/translations"
[/textdomain]
[campaign]
	#textdomain wesnoth-3rd_Army
	id=3rd_army
	name= _ "3rd Army"
	abbrev= - "3rdA"
	define=CAMPAIGN_3RD_ARMY
	icon=
	image=
	first scenario=01_First_Contact
	description= _ "Trials and tribulations of the 3rd Army in the Great Midgard War"
	{CAMPAIGN_DIFFICULTY EASY "units/human-loyalists/horseman/horseman.png~RC(magenta>red)" ( _ "Recruit") ( _ "Beginner")} {DEFAULT_DIFFICULTY}
	{CAMPAIGN_DIFFICULTY NORMAL "units/human-loyalists/longbowman.png~RC(magenta>blue)" _"Veteran" _"Intermediate"}
    {CAMPAIGN_DIFFICULTY HARD "units/human-loyalists/masterbowman.png~RC(magenta>blue)" _"Commander" _"Hard"}
[/campaign]

#ifdef CAMPAIGN_3RD_ARMY

	[binary_path]
		path=data/add-ons/3rd_army
	[/binary_path]

	{~add-ons/3rd_army/macros}
	{~add-ons/3rd_army/utils}
	
	{~add-ons/my_first_campaign/scenarios}
#endif

This one crashes the game (with no explanation) when I select "Campaign," so I've pulled it aside to edit.

And here is the .cfg for the first scenario ("First Contact")

Code: Select all


# First planned scenario of the campaigns of 3rd Army in the Great Midgard War.  WIP.
# The map and scenario are mostly for aesthetic purposes.  This scenario, in its original
# form, is not intended to be balanced.  The advantage is all with the humans here. This 
# is because it will reflect the initial meeting engagement between the 3rd Army and an
# Orc raiding party. Humans can draw on all the resources of the 3rd Army to throw into
# the fight, but the Orcs are limited here because their main force is elsewhere. This
# will change in later scenaria, as they are completed.
#
#textdomain wesnoth-first_contact
[scenario]
	id=01_First_Contact
	next_scenario=null
	
	name= _ "First Contact"
	map_file=First_Contact.map
	turns=90
	
	difficulties=EASY,NORMAL,HARD
	
       {DEFAULT_SCHEDULE}

 
	[event]
    name=prestart
    [objectives]
      side=1
      [objective]
        description= _ "Kill Garlik"
        condition=win
      [/objective]
      [objective]
        description= _ "Death of Farnsworth"
        condition=lose
      [/objective]
	  [objective]
        description= _ "Death of Jeremiah"
        condition=lose
      [/objective]
      [objective]
        description= _ "Turns run out"
        condition=lose
      [/objective]
    [/objectives]
  [/event]
    
	
	[story]
		[part]
			music=revelation.ogg
			story="As 3rd Army was moving North of the White River in Midgard, they encountered a raiding party of Orcs near the town of Alton on the Mona river. The army hastened to reinforce the advanced guard and eventually drove the orcs out of the town and back to Branston, where the orc leader was slain."
		[/part]
	[/story]
	
	# Now for the good guys:
	
	[side]
        side=1
        controller=human
		user_team_name=_ "3rd Army"
		type=Dragoon
		id=Farnsworth
		name=_ "Farnsworth"
		unrenamable=yes
		[modifications]
			{TRAIT_LEADER}
			{TRAIT_RESILIENT}
		[/modifications]
		canrecruit=yes
        recruit=Horseman,Cavalryman,Bowman,Spearman,Fencer,Heavy Infantryman,Mage
		
		[unit]
            side=1
            type=Dragoon
            id=Jeremiah
            name= _ "Jeremiah"
            unrenamable=yes
            x,y=4,92
            [modifications]
                {TRAIT_LEADER}
                {TRAIT_RESILIENT}
            [/modifications]
			canrecruit=yes
			recruit=Horseman,Cavalryman,Bowman,Spearman,Fencer,Heavy Infantryman,Mage
        [/unit]
		
		{GOLD 200 100 50}
		{INCOME 12 6 2}
	[/side]
	
	# The black hats
	
	[side]
		side=2
		type=Orcish Warrior
		id=Garlik
		name= _ "Garlik"
		[modifications]
			{TRAIT_LEADER}
			{TRAIT_STRONG}
		[modifications]
		canrecruit=yes
		recruit=Orcish Archer,Orcish Grunt,Orcish Assassin,Goblin Spearman,Troll Whelp,Wolf Rider
		
		{GOLD 50 25 10}
		(INCOME 6 2 1}
	[/side]
	
If I try to start a MP game to test the scenario, it tells me that the first Macro is "missing" and exits. If I remove the first macro, it does the same for the next macro, etc, so presumably it cannot find any of the macros.

Now, I've constructed these .cfg files by following the wiki and referring to campaigns included in vanilla. I have not, as yet, downloaded any add-ons or altered the stock game in any way (save for creating these .cfg files, which are now outside the game anyway to keep it from crashing).
The wiki appears to be rather out-of-date, version-wise, as there are differences in syntax between its example and the campaigns in the game. All of which use tons of macros that are not defined anywhere. As the campaign.cfg also calls macros, I'm guessing the game can't find those, either. Although it has no trouble with the macros in the supplied campaigns.

There are probably some syntax errors in the code, but first things first: why can't the game find the macros?

-- Mal
Last edited by malthaussen on April 10th, 2024, 10:46 pm, edited 2 times in total.
"Of two choices, I always take the third."
User avatar
Ravana
Forum Moderator
Posts: 3018
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: Okay, what's up with the macros

Post by Ravana »

first scenario=01_First_Contact is invalid wml, so this campaign should not load, but no wml should be able to make game crash.
User avatar
malthaussen
Posts: 36
Joined: April 6th, 2024, 11:05 pm

Re: Okay, what's up with the macros

Post by malthaussen »

So, what is the proper syntax? And the game assuredly crashed when I selected "Campaign," and now does not since I pulled the campaign file from the Documents library.

-- Mal
"Of two choices, I always take the third."
User avatar
Ravana
Forum Moderator
Posts: 3018
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: Okay, what's up with the macros

Post by Ravana »

first_scenario
User avatar
malthaussen
Posts: 36
Joined: April 6th, 2024, 11:05 pm

Re: Okay, what's up with the macros

Post by malthaussen »

Bah, humbug! Oh, well, at least I'm not using punch cards to write the code.

-- Mal
"Of two choices, I always take the third."
User avatar
malthaussen
Posts: 36
Joined: April 6th, 2024, 11:05 pm

Re: Okay, what's up with the macros

Post by malthaussen »

Well that change kept the game from crashing, anyway. Progress!

-- Mal
"Of two choices, I always take the third."
User avatar
malthaussen
Posts: 36
Joined: April 6th, 2024, 11:05 pm

Re: Okay, what's up with the macros

Post by malthaussen »

Well, this is interesting.

I noted that a scenario started with the Editor contained a warning to not use macros. And I did, in fact, make the original .cfg file using the editor.

So, what I did, I copied a scenario.cfg from the game, deleted the contents, and pasted the text from my original .cfg file into it, renaming it appropriately. I then swapped the files, and viola (sorta), the MP routine didn't complain about the {DEFAULT_SCHEDULE} macro in the new version, while still insisting that the macro did not exist in the original version. Progress, I thought.

Not much, though. It still doesn't like any other macros I use in the scenario, even though these are standard macros (eg, GOLD). But at least it doesn't complain about {DEFAULT_SCHEDULE}

Then I decided to try something weird, and just copied a scenario from the game into the editor folder. And now the MP routine complains about that scenario's macros.

-- Mal
"Of two choices, I always take the third."
User avatar
Pentarctagon
Project Manager
Posts: 5567
Joined: March 22nd, 2009, 10:50 pm
Location: Earth (occasionally)

Re: Okay, what's up with the macros

Post by Pentarctagon »

The editor doesn't allow macros because it would need to parse them into plain WML to be able to read the file, but then it has no way to convert them back to macros later when the scenario is saved.

If you want to use things that the editor doesn't understand/allow, then they should be put into a separate file and included via the include_file attribute.
99 little bugs in the code, 99 little bugs
take one down, patch it around
-2,147,483,648 little bugs in the code
User avatar
malthaussen
Posts: 36
Joined: April 6th, 2024, 11:05 pm

Re: Okay, what's up with the macros

Post by malthaussen »

But why does the MP routine not find the macros? That should have nothing to do with the editor.

And to put a fine point on it, why is the MP routine now not complaining about the {DEFAULT_SCHEDULE} macro, but does fail to find other macros (eg, GOLD?).

I can't very well test my scenarios if the MP routine fails to find the macros.

-- Mal
"Of two choices, I always take the third."
User avatar
Pentarctagon
Project Manager
Posts: 5567
Joined: March 22nd, 2009, 10:50 pm
Location: Earth (occasionally)

Re: Okay, what's up with the macros

Post by Pentarctagon »

What do you mean by "MP routine"?
99 little bugs in the code, 99 little bugs
take one down, patch it around
-2,147,483,648 little bugs in the code
User avatar
malthaussen
Posts: 36
Joined: April 6th, 2024, 11:05 pm

Re: Okay, what's up with the macros

Post by malthaussen »

I mean, when I start the game and select "Multiplayer," so I can test the scenario. As stated in the first post of this thread.

-- Mal
"Of two choices, I always take the third."
User avatar
Pentarctagon
Project Manager
Posts: 5567
Joined: March 22nd, 2009, 10:50 pm
Location: Earth (occasionally)

Re: Okay, what's up with the macros

Post by Pentarctagon »

I'm a bit lost. Where is the scenario file that's causing the issue located? Is it in the editor's scenario folder or your add-on's folder?
99 little bugs in the code, 99 little bugs
take one down, patch it around
-2,147,483,648 little bugs in the code
User avatar
malthaussen
Posts: 36
Joined: April 6th, 2024, 11:05 pm

Re: Okay, what's up with the macros

Post by malthaussen »

It is in Wesnoth 1.18/editor/scenarios, located in the Documents/My Games folder. It is also cc'd to the folder for the campaign I am working on, which would be under Wesnoth 1.18/3rd Army Campaign, which is the folder for said campaign.

To clarify: I start Wesnoth 1.18, select "Multiplayer," and "Local Game," and it said the macro {DEFAULT_SCHEDULE} was missing. Then I made a fix to the campaign .cfg, and now it doesn't complain about {DEFAULT_SCHEDULE), but the next macro the scenario calls {GOLD).

If I remove all macros but (DEFAULT_SCHEDULE}, then "Multiplayer" works fine, but my scenario is not listed among the playable options (nor is the campaign). So what do we conclude? "Multiplayer" clearly sees my scenario, or would not return an error and revert to the main menu. But if the scenario does not have the error Multiplayer formerly returned, it does not add it to the playable list.

As I say above, I also for kicks copied one of the scenarios included with the game to the "Wesnoth 1.18/editor/scenarios" folder just to see what would happen, and Multiplayer immediately says the first macro in that scenario is "missing" and reverts to the main menu.

As a further test, I downloaded one of the user-created campaigns, "A Fiery Birth," which contains many macros in both campaign and scenarios, and Multiplayer has no problem with it and lists the campaign for play. That, of course, is located in the Data/add-ons folder of the Wesnoth 1.18 folder.
Then to further check the program's behavior, I copied one of the scenarios from this campaign into the Wesnoth 1.18/editor/scenarios folder, and again started Multipayer, which now cannot find the macros in that file. It just doesn't seem to find the macros in any scenarios, except for (DEFAULT_SCHEDULE}, and it seems very weird that a fix to the campaign .cfg would make Multiplayer recognize that macro and no others.

So, let's go back to first principles. How is a user supposed to test if his scenario is working properly before inflicting it on the public? Because apparently trying to play it in Multiplayer is a no-go.

-- Mal

-- Mal
"Of two choices, I always take the third."
Post Reply