unknown conditional WML: [set_variable]

The place to post your WML questions and answers.

Moderators: Forum Moderators, Developers

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
Gwledig
Posts: 414
Joined: March 30th, 2009, 5:10 pm
Location: UK

unknown conditional WML: [set_variable]

Post by Gwledig » July 12th, 2019, 9:03 am

I am getting this error on all my mods, with a number next to the side e.g. 36 or 25 depending on the map and usually a repeated error with 6 next to it:

Code: Select all

unknown conditional WML: [set_variable] 36
unknown conditional WML: [set_variable] 6
I noticed posts suggesting that in 1.14 [set_variable] has been deprecated others suggest changing [set_variable] to [variable] I did the latter then got an error that [variable] was invalid WML.

I suspect, given the number shown which is different depending on the different map played, that the 1st error is related to a {VARIABLE...} macro shown when calculating bonus gold when map villages belong to a player e.g. {VARIABLE_OP income_bonus add 9}, these occur in each map and the number of villas varies depending on the map, so is probably the source of the 1st error e.g. 36. Here is an example:

Code: Select all

#define CALCULATE_INCOME_BONUS_XANTHOR SIDE
		
		{VARIABLE income_bonus 0}

		#Bovinia
		[if]
			[have_location]
				x=2
				y=1
				owner_side={SIDE}
			[/have_location]
			[have_location]
				x=4
				y=4
				owner_side={SIDE}
			[/have_location]
			[have_location]
				x=4
				y=9
				owner_side={SIDE}
			[/have_location]
			[have_location]
				x=10
				y=1
				owner_side={SIDE}
			[/have_location]
			[have_location]
				x=11
				y=6
				owner_side={SIDE}
			[/have_location]
			[have_location]
				x=16
				y=1
				owner_side={SIDE}
			[/have_location]

			[then]
				{VARIABLE_OP income_bonus add 9}
			[/then]
		[/if]

I also read somewhere that the way variables are set has been affected in 1.14 when including in an [if] condition.

if I can get my head around why this is happening in this example and any idea of a replacement expression supported in 1.14 I should be able to look for similar instances across my mods and fix this... I'm hoping for a fix I can search & replace like the way the macro is shown, otherwise it's a lot of typing :/ Of course I could be on the wrong track and it could be variables I have in other parts of the mod's WML... I'm not that familar with debugging at the moment so I can't recall how to pinpoint the error, it's quite a few years since I re-built all the conquest WML and I'm feeling a bit rusty with the whole thing.
Maintainer of: Conquest+ Classic, Conquest+ Space/Ranged, Chaoz Battle of the Wizards, Lazersquad (squad game), WesCraft (building multiplayer scenario)

User avatar
octalot
Code Contributor
Posts: 329
Joined: July 17th, 2010, 7:40 pm

Re: unknown conditional WML: [set_variable]

Post by octalot » July 12th, 2019, 9:07 am

The tags [set_variable] and [variable] are for two different purposes:
  • [set_variable] sets (changes) the value
  • [variable] is for testing what the value is, and doesn't change it. This tag is one of the Conditional WML tags.
Did you do a global search-and-replace changing [variable] to [set_variable]? The error unknown conditional WML: [set_variable] is probably that you had [if][variable], but it's been changed to [if][set_variable].

User avatar
Gwledig
Posts: 414
Joined: March 30th, 2009, 5:10 pm
Location: UK

Re: unknown conditional WML: [set_variable]

Post by Gwledig » July 12th, 2019, 9:16 am

I am pretty sure that the unknown conditional WML: [set_variable] 6 I see is caused by this

Code: Select all

#define COUNT_PLAYERS

#count players
{VARIABLE playersingame 0}

[if]
[have_unit]
side=1
[/have_unit]
[then]
{VARIABLE_OP playersingame add 1}
[/then]
[/if]

[if]
[have_unit]
side=2
[/have_unit]
[then]
{VARIABLE_OP playersingame add 1}
[/then]
[/if]

[if]
[have_unit]
side=3
[/have_unit]
[then]
{VARIABLE_OP playersingame add 1}
[/then]
[/if]

[if]
[have_unit]
side=4
[/have_unit]
[then]
{VARIABLE_OP playersingame add 1}
[/then]
[/if]

[if]
[have_unit]
side=5
[/have_unit]
[then]
{VARIABLE_OP playersingame add 1}
[/then]
[/if]

[if]
[have_unit]
side=6
[/have_unit]
[then]
{VARIABLE_OP playersingame add 1}
[/then]
[/if]


#enddef
The number of instances for the 2 errors seem to match the number of instances in this WML file and in the map file which varies with the number of villages, so it seems all the errors are caused by {VARIABLE_OP appearing in an [if]

I do have other instances of [set_variable] but the only one appearing in an if is this

Code: Select all

#if the number of vilas is greater than 100 set to 100 only, otherwise too many vilas are allocated
[if]
[variable]
name=division
greater_than=110
[/variable]
[then]
[set_variable]
name=division
value=110
[/set_variable]
[/then]
[/if]
Last edited by Gwledig on July 12th, 2019, 10:17 am, edited 3 times in total.
Maintainer of: Conquest+ Classic, Conquest+ Space/Ranged, Chaoz Battle of the Wizards, Lazersquad (squad game), WesCraft (building multiplayer scenario)

User avatar
octalot
Code Contributor
Posts: 329
Joined: July 17th, 2010, 7:40 pm

Re: unknown conditional WML: [set_variable]

Post by octalot » July 12th, 2019, 9:55 am

What does the code around where you use {COUNT_PLAYERS} look like?

Confusingly, the {VARIABLE name value} macro expands to a [set_variable], not to [variable]. My current guess is that the error looks like (spoilered so that it doesn't distract anyone else if the guess is wrong):
Spoiler:

User avatar
Gwledig
Posts: 414
Joined: March 30th, 2009, 5:10 pm
Location: UK

Re: unknown conditional WML: [set_variable]

Post by Gwledig » July 12th, 2019, 10:13 am

I now don't think it is caused in count players from what you have said -

Code: Select all

#define COUNT_PLAYERS

#count players
{VARIABLE playersingame 0}

[if]
[have_unit]
side=1
[/have_unit]
[then]
{VARIABLE_OP playersingame add 1}
[/then]
[/if]

[if]
[have_unit]
side=2
[/have_unit]
[then]
{VARIABLE_OP playersingame add 1}
[/then]
[/if]

[if]
[have_unit]
side=3
[/have_unit]
[then]
{VARIABLE_OP playersingame add 1}
[/then]
[/if]

[if]
[have_unit]
side=4
[/have_unit]
[then]
{VARIABLE_OP playersingame add 1}
[/then]
[/if]

[if]
[have_unit]
side=5
[/have_unit]
[then]
{VARIABLE_OP playersingame add 1}
[/then]
[/if]

[if]
[have_unit]
side=6
[/have_unit]
[then]
{VARIABLE_OP playersingame add 1}
[/then]
[/if]


#enddef


if {variable... is correctly adding [set variable... which seems ok for use in IF (also reflecting my need to change variable values) then the issue for the unknown conditional WML: [set_variable] (6) may be coming from elsewhere such as

Code: Select all

#define STANDARD_GET_SIDES SIDE_CHECK_ORDER

{VARIABLE_OP currentside value 0}
{VARIABLE stopcheckcurrentside 0}

[if]
[have_unit]
side=1
[/have_unit]
[and]
{VARIABLE stopcheckcurrentside 0}
[/and]
[then]
{VARIABLE_OP currentside value {SIDE_CHECK_ORDER}}
{VARIABLE_OP stopcheckcurrentside value 1}
[/then]
[/if]

[if]
[have_unit]
side=2
[/have_unit]
[and]
{VARIABLE stopcheckcurrentside 0}
[/and]
[then]
{VARIABLE_OP currentside value {SIDE_CHECK_ORDER}}
{VARIABLE_OP stopcheckcurrentside value 1}
[/then]
[/if]

[if]
[have_unit]
side=3
[/have_unit]
[and]
{VARIABLE stopcheckcurrentside 0}
[/and]
[then]
{VARIABLE_OP currentside value {SIDE_CHECK_ORDER}}
{VARIABLE_OP stopcheckcurrentside value 1}
[/then]
[/if]

[if]
[have_unit]
side=4
[/have_unit]
[and]
{VARIABLE stopcheckcurrentside 0}
[/and]
[then]
{VARIABLE_OP currentside value {SIDE_CHECK_ORDER}}
{VARIABLE_OP stopcheckcurrentside value 1}
[/then]
[/if]

[if]
[have_unit]
side=5
[/have_unit]
[and]
{VARIABLE stopcheckcurrentside 0}
[/and]
[then]
{VARIABLE_OP currentside value {SIDE_CHECK_ORDER}}
{VARIABLE_OP stopcheckcurrentside value 1}
[/then]
[/if]

[if]
[have_unit]
side=6
[/have_unit]
[and]
{VARIABLE stopcheckcurrentside 0}
[/and]
[then]
{VARIABLE_OP currentside value {SIDE_CHECK_ORDER}}
{VARIABLE_OP stopcheckcurrentside value 0}
[/then]
[/if]

{VARIABLE_OP stopcheckcurrentside value 0}

#enddef
looking at the above, this may be using the wrong form of variable in an IF e.g.

Code: Select all

[if]
[have_unit]
side=1
[/have_unit]
[and]
{VARIABLE stopcheckcurrentside 0}
[/and]
...ie if its mistakenly trying to set variable in the AND when it should be checking...

I have another smilar script which I think is used for victory conditions, so may not be triggering at this point in my testing but might present the same error

Code: Select all

#define STANDARD_GET_LAST_SIDE

{VARIABLE_OP lastcurrentside value 0}
{VARIABLE laststopchecklastcurrentside 0}

[if]
[have_unit]
side=1
[/have_unit]
[and]
{VARIABLE laststopchecklastcurrentside 0}
[/and]
[then]
{VARIABLE_OP lastcurrentside value 1}
{VARIABLE_OP laststopchecklastcurrentside value 1}
[/then]
[/if]

[if]
[have_unit]
side=2
[/have_unit]
[and]
{VARIABLE laststopchecklastcurrentside 0}
[/and]
[then]
{VARIABLE_OP lastcurrentside value 2}
{VARIABLE_OP laststopchecklastcurrentside value 1}
[/then]
[/if]

[if]
[have_unit]
side=3
[/have_unit]
[and]
{VARIABLE laststopchecklastcurrentside 0}
[/and]
[then]
{VARIABLE_OP lastcurrentside value 3}
{VARIABLE_OP laststopchecklastcurrentside value 1}
[/then]
[/if]

[if]
[have_unit]
side=4
[/have_unit]
[and]
{VARIABLE laststopchecklastcurrentside 0}
[/and]
[then]
{VARIABLE_OP lastcurrentside value 4}
{VARIABLE_OP laststopchecklastcurrentside value 1}
[/then]
[/if]

[if]
[have_unit]
side=5
[/have_unit]
[and]
{VARIABLE laststopchecklastcurrentside 0}
[/and]
[then]
{VARIABLE_OP lastcurrentside value 5}
{VARIABLE_OP laststopchecklastcurrentside value 1}
[/then]
[/if]

[if]
[have_unit]
side=6
[/have_unit]
[and]
{VARIABLE laststopchecklastcurrentside 0}
[/and]
[then]
{VARIABLE_OP lastcurrentside value 6}
[/then]
[/if]

{VARIABLE_OP laststopchecklastcurrentside value 0}

#enddef
It looks pretty certain somehting is happening for the error with the bigger number which changes depending on the map, e.g. unknown conditional WML: [set_variable] (26)

I'm guessing it may be possible to pinpoint what part of the map file is causing this...

Code: Select all

[multiplayer]
id=Conquest+_Xanthor
name=_"Conquest (Original Gameplay) Xanthor NO DOWNLOAD NEEDED"
description=_ "Conquest (Original Gameplay) Xanthor! Defeat your opponents in this Risk-inspired game. Factions used: Humans, Elves, Orcs, Mermen.
For 2-4 players"

	map_data="{~add-ons/Conquest_original_gameplay/maps/xanthor.map}"

	{INTRO_STORY}
{DEFAULT_SCHEDULE}
	{DEFAULT_MUSIC_PLAYLIST}

	{CONQUEST_BASE}
	{OBJECTIVES_NOTE_MAP_BY (Lich_Lord, modified by Gwledig)}

{WORK}
{SELECT_LENGTH}	

	{RECRUIT_MENU_HUMANS Gg^Vh}
	{RECRUIT_MENU_ELVES Gg^Ve}
	{RECRUIT_MENU_ORCS Gg^Vc}
	{RECRUIT_MENU_MERMEN Ww^Vm}
	

{BOAT_MENU}
{CONQUEST_BOATS *^V*}

	        {AI_PLACEMENT}
	
	#Player militia modification
	[event]
	name=turn 1 refresh  
	first_time_only=no
	{MODIFY_UNIT (role=Peon) race "human"}
	#{MODIFY_UNIT (role=Peon) type "Spearman"}
	{MODIFY_UNIT (role=Peon) overlays "units/human-loyalists/spearman.png"}
	{MODIFY_UNIT (role=Peon) name "Militia"}
	[redraw]  
	side=1-6
[/redraw]
	fire_event=yes
	[/event]
	
	#AI militia modification
	[event]
	name=side 1 turn 2  refresh 
	first_time_only=yes
	{MODIFY_UNIT (role=AIPeon) race "human"}
	#{MODIFY_UNIT (role=AIPeon) type "Spearman"}
	{MODIFY_UNIT (role=AIPeon) overlays "units/human-loyalists/spearman.png"}
	{MODIFY_UNIT (role=AIPeon) name "Militia"}
	fire_event=yes
	[/event]

#values: menu name, number of vilas, standard mode 0 or 1, capitol mode 0 or 1, realm mode 0 or 1
{GAME_MENU 23 1 1 0}

   		
	[event]
		name=side turn
		first_time_only=no
		
		#Bovinia
		{SET_LABEL 2 1 ("Nurtz (Bovinia)")}
		{SET_LABEL 4 4 ("Leka (Bovinia)")}
		{SET_LABEL 4 9 ("Liptoma (Bovinia)")}
		{SET_LABEL 10 1 ("Semna (Bovinia)")}
		{SET_LABEL 11 6 ("Haboo (Bovinia)")}
		{SET_LABEL 16 1 ("Boville (Bovinia)")}
		#Cedarwood
		{SET_LABEL 2 17 ("Franluria (Cedarwood)")}
		{SET_LABEL 10 14 ("Bandir (Cedarwood)")}
		{SET_LABEL 10 19 ("Eleusinia (Cedarwood)")}
		{SET_LABEL 4 23 ("Mapshar (Cedarwood)")}
		#Timburrow
		{SET_LABEL 20 15 ("Woodstock (Timburrow)")}
		{SET_LABEL 19 21 ("Menicius (Timburrow)")}
		#Razalin
		{SET_LABEL 36 6 ("Reza (Razalin)")}
		{SET_LABEL 38 2 ("Mabinogion (Razalin)")}
		{SET_LABEL 31 2 ("Xunt (Razalin)")}
		{SET_LABEL 27 7 ("Mancheat (Razalin)")}
		{SET_LABEL 25 3 ("Oroman (Razalin)")}
		#Mergrad
		{SET_LABEL 33 25 ("Mermansk (Mergrad)")}
		{SET_LABEL 38 25 ("Swatra (Mergrad)")}
		#Cataline
		{SET_LABEL 26 24 ("Pangu (Cataline)")}
		{SET_LABEL 31 20 ("Shakari (Cataline)")}
		{SET_LABEL 38 19 ("Handhala (Cataline)")}
		#Zubnir
		{SET_LABEL 37 12 ("Elyon (Zubnir)")}
		{SET_LABEL 32 13 ("Atherton (Zubnir)")}

		{SET_LABEL 3 27 ("<b>1. Bovinia</b>")}
		{SET_LABEL 4 27 ("<small>9 Gold</small>")}
		{SET_LABEL 3 28 ("<b>2. Razalin</b>")}
		{SET_LABEL 4 28 ("<small>7 Gold</small>")}
		{SET_LABEL 3 29 ("<b>3. Cedarwood</b>")}
		{SET_LABEL 4 29 ("<small>5 Gold</small>")}
		{SET_LABEL 3 30 ("<b>4. Cataline</b>")}
		{SET_LABEL 4 30 ("<small>4 Gold</small>")}

		{SET_LABEL 7 27 ("<b>5. Timburrow</b>")}
		{SET_LABEL 8 27 ("<small>2 Gold</small>")}
		{SET_LABEL 7 28 ("<b>6. Mergrad</b>")}
		{SET_LABEL 8 28 ("<small>2 Gold</small>")}
		{SET_LABEL 7 29 ("<b>7. Zubnir</b>")}
		{SET_LABEL 8 29 ("<small>2 Gold</small>")}
	[/event]



	#define CALCULATE_INCOME_BONUS_XANTHOR SIDE
		
		{VARIABLE income_bonus 0}

		#Bovinia
		[if]
			[have_location]
				x=2
				y=1
				owner_side={SIDE}
			[/have_location]
			[have_location]
				x=4
				y=4
				owner_side={SIDE}
			[/have_location]
			[have_location]
				x=4
				y=9
				owner_side={SIDE}
			[/have_location]
			[have_location]
				x=10
				y=1
				owner_side={SIDE}
			[/have_location]
			[have_location]
				x=11
				y=6
				owner_side={SIDE}
			[/have_location]
			[have_location]
				x=16
				y=1
				owner_side={SIDE}
			[/have_location]

			[then]
				{VARIABLE_OP income_bonus add 9}
			[/then]
		[/if]

		#Cederwood
		[if]
			[have_location]
				x=2
				y=17
				owner_side={SIDE}
			[/have_location]
			[have_location]
				x=10
				y=14
				owner_side={SIDE}
			[/have_location]
			[have_location]
				x=10
				y=19
				owner_side={SIDE}
			[/have_location]
			[have_location]
				x=4
				y=23
				owner_side={SIDE}
			[/have_location]
			[then]
				{VARIABLE_OP income_bonus add 5}
			[/then]
		[/if]

		#Razalim
		[if]
			[have_location]
				x=36
				y=6
				owner_side={SIDE}
			[/have_location]
			[have_location]
				x=38
				y=2
				owner_side={SIDE}
			[/have_location]
			[have_location]
				x=31
				y=2
				owner_side={SIDE}
			[/have_location]
			[have_location]
				x=27
				y=7
				owner_side={SIDE}
			[/have_location]
			[have_location]
				x=25
				y=3
				owner_side={SIDE}
			[/have_location]
			[then]
				{VARIABLE_OP income_bonus add 7}
			[/then]
		[/if]

		#Cataline
		[if]
			[have_location]
				x=26
				y=24
				owner_side={SIDE}
			[/have_location]
			[have_location]
				x=31
				y=20
				owner_side={SIDE}
			[/have_location]
			[have_location]
				x=38
				y=19
				owner_side={SIDE}
			[/have_location]
			[then]
				{VARIABLE_OP income_bonus add 4}
			[/then]
		[/if]

		#Mergrad
		[if]
			[have_location]
				x=33
				y=25
				owner_side={SIDE}
			[/have_location]
			[have_location]
				x=38
				y=25
				owner_side={SIDE}
			[/have_location]
			[then]
				{VARIABLE_OP income_bonus add 2}
			[/then]
		[/if]

		#Timburrow
		[if]
			[have_location]
				x=20
				y=15
				owner_side={SIDE}
			[/have_location]
			[have_location]
				x=19
				y=21
				owner_side={SIDE}
			[/have_location]
			[then]
				{VARIABLE_OP income_bonus add 2}
			[/then]
		[/if]

		#Zubnir
		[if]
			[have_location]
				x=37
				y=12
				owner_side={SIDE}
			[/have_location]
			[have_location]
				x=32
				y=13
				owner_side={SIDE}
			[/have_location]
			[then]
				{VARIABLE_OP income_bonus add 2}
			[/then]
		[/if]

		[modify_side]
			side={SIDE}
			income=$income_bonus
		[/modify_side]
	#enddef

	[event]
		name=capture
		first_time_only=no
		
		{CALCULATE_INCOME_BONUS_XANTHOR 1}
		{CALCULATE_INCOME_BONUS_XANTHOR 2}
		{CALCULATE_INCOME_BONUS_XANTHOR 3}
		{CALCULATE_INCOME_BONUS_XANTHOR 4}
	[/event]
	[event]
		name=side turn
		first_time_only=no
		
		{CALCULATE_INCOME_BONUS_XANTHOR $side_number}
	[/event]
[/multiplayer]
Maintainer of: Conquest+ Classic, Conquest+ Space/Ranged, Chaoz Battle of the Wizards, Lazersquad (squad game), WesCraft (building multiplayer scenario)

User avatar
Gwledig
Posts: 414
Joined: March 30th, 2009, 5:10 pm
Location: UK

Re: unknown conditional WML: [set_variable]

Post by Gwledig » July 12th, 2019, 10:32 am

I seem to be making progress by converting

Code: Select all

[and]
{VARIABLE stopcheckcurrentside 0}
[/and]
to the following format:

Code: Select all

and
[variable]
name=stopcheckcurrentside 
value=0
[/variable]
and
..just a case of checking where a {VARIABLE which should be checking is used and changing this everywhere... perhaps this has always not functioned previoulsy and just didn't get error-reported, perhaps it didn't affect gameplay so we didn't notice...
Maintainer of: Conquest+ Classic, Conquest+ Space/Ranged, Chaoz Battle of the Wizards, Lazersquad (squad game), WesCraft (building multiplayer scenario)

User avatar
josteph
Developer
Posts: 616
Joined: August 19th, 2017, 6:58 pm

Re: unknown conditional WML: [set_variable]

Post by josteph » July 12th, 2019, 11:25 am

Are you just looking for {VARIABLE_CONDITIONAL stopcheckcurrentside equals 0}? Previously [and][set_variable] would have been treated like an empty [and].

A few tips: when you post code blocks, post them indented for us; post the complete error message verbatim; say what version of wesnoth you use (1.14.what?); post minimal example code that reproduces the error message.

User avatar
Gwledig
Posts: 414
Joined: March 30th, 2009, 5:10 pm
Location: UK

Re: unknown conditional WML: [set_variable]

Post by Gwledig » July 12th, 2019, 12:44 pm

Thats really useful thanks
Maintainer of: Conquest+ Classic, Conquest+ Space/Ranged, Chaoz Battle of the Wizards, Lazersquad (squad game), WesCraft (building multiplayer scenario)

User avatar
octalot
Code Contributor
Posts: 329
Joined: July 17th, 2010, 7:40 pm

Re: unknown conditional WML: [set_variable]

Post by octalot » July 12th, 2019, 6:37 pm

This is unrelated to the error that you're searching for, but Wesnoth 1.14 supports the [for] tag, which can be an easy way to avoid having a copy of code for each team. For example:

Code: Select all

#define COUNT_PLAYERS

# count players
{VARIABLE playersingame 0}

[for]
    start=1
    end=6
    [do]
        [if]
            [have_unit]
                side=$i
            [/have_unit]
            [then]
                {VARIABLE_OP playersingame add 1}
            [/then]
        [/if]
    [/do]
[/for]
#enddef

User avatar
Gwledig
Posts: 414
Joined: March 30th, 2009, 5:10 pm
Location: UK

Re: unknown conditional WML: [set_variable]

Post by Gwledig » July 13th, 2019, 11:21 am

Thanks octalot I'll see about replacing areas where this could be used

In terms of unknown conditional WML: [set_variable] I think I was copying and pasting unit modification WML used principally for recruiting on the fly in the MP scenario, i.e. copying this for modifying player's commander units spawned on startup, I think these are where all theunknown conditional WML is taking place, because the store/unstore unit behaviour isn't needed for these commander modifications, the unit already existed and could explain why the variable was empty. The same issue happened on a lot of my other mods, as I used the same principle, most of them work on the basis of a commander summoning units like Chaoz and Conquest Space, in fact the whole section where store/unstore is used in such MWL was redundant and had no effect when removed, I guess it was just ignored previosly but in 1.14 produces this error, but was just reporting and didn't actually stop anything working as far as I know.
Maintainer of: Conquest+ Classic, Conquest+ Space/Ranged, Chaoz Battle of the Wizards, Lazersquad (squad game), WesCraft (building multiplayer scenario)

Post Reply