Potential bug in wml.lua

Having trouble with the game? Report issues and get help here. Read this first!

Moderator: Forum Moderators

Forum rules
Before reporting issues in this section, you must read the following topic:
Post Reply
User avatar
Heindal
Posts: 1344
Joined: August 11th, 2011, 9:25 pm
Location: Germany, Karlsruhe
Contact:

Potential bug in wml.lua

Post by Heindal »

Currently I'm receiving this odd bug in one of my campaigns:

Code: Select all

20220124 18:04:24 error scripting/lua: lua/core/wml.lua:232: bad argument #2 to 'set_variable_local' (WML table or scalar expected, got table)
stack traceback:
	[C]: in function 'wml.set_variable'
	lua/core/wml.lua:232: in metamethod 'newindex'
	lua/wml-utils.lua:47: in field 'write'
	lua/wml-tags.lua:406: in local 'cmd'
	lua/wml-utils.lua:144: in field 'handle_event_commands'
	lua/wml-flow.lua:19: in local 'cmd'
	lua/wml-utils.lua:144: in field 'handle_event_commands'
	lua/wml-flow.lua:5: in function <lua/wml-flow.lua:4>
Once I start the campaign again, the lua error no longer occurs, even so I haven't change the code at all.
The culprit seems to be this piece of code.

Code: Select all

	
	
	-- Get and set variables via wml.variables[variable_path]
	wml.variables = setmetatable({}, {
		__metatable = "WML variables",
		__index = function(_, key)
			return get_variable_local(key)
		end,
		__newindex = function(_, key, value)
			[b]set_variable_local(key, value)[/b]
		end
	})
It is triggered when I use [store_unit]. E.g.:

Code: Select all

			[store_unit]
				kill=no
				variable=temp
				[filter]
					x=$x1
					y=$y1
				[/filter]
			[/store_unit]
			[set_variable]
				name=temp.moves
				to_variable=temp.max_moves
			[/set_variable]
			[unstore_unit]
				find_vacant=no
				variable=temp
			[/unstore_unit]
			
			[clear_variable]
				name=temp
			[/clear_variable]

The same source code is used in other campaigns without a problem. It doesn't matter if I use an id in the filter or not. However it works as it should after the campaign is restarted. The only difference is, that I used #ifdef EASY to define the hero character in this campaign.
The future belongs to those, who believe in the beauty of their dreams.
Developer of: Trapped, Five Fates, Strange Legacy, Epical, UR Epic Era
Dungeonmasters of Wesnoth, Wild Peasants vs Devouring Corpses, Dwarf Dwarfson Dwarvenminer
User avatar
Ravana
Forum Moderator
Posts: 2948
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: Potential bug in wml.lua

Post by Ravana »

In such case you could change core file to show the problematic value. Message suggests some part of your unit is not stored in expected format.
User avatar
Heindal
Posts: 1344
Joined: August 11th, 2011, 9:25 pm
Location: Germany, Karlsruhe
Contact:

Re: Potential bug in wml.lua

Post by Heindal »

Will check this, however it doesn't make sense as the 'unit' itself hasn't changed and the code hasn't changed, when I restart the campaign.
I however find in questionable that a lua script is parsing every variable I already clearly defined using wml.

The only thing I can assume is that the script is confused by a flexible unit type, which is set by #ifdef.
When reloading using the same unit type and difficulty the unit stays the same.

At least that might explain the other bug, I've seen in Five Fates which produces unsaveable games.
The future belongs to those, who believe in the beauty of their dreams.
Developer of: Trapped, Five Fates, Strange Legacy, Epical, UR Epic Era
Dungeonmasters of Wesnoth, Wild Peasants vs Devouring Corpses, Dwarf Dwarfson Dwarvenminer
User avatar
Ravana
Forum Moderator
Posts: 2948
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: Potential bug in wml.lua

Post by Ravana »

That makes sense, if game is unable to save your unit as WML for variable, then it will fail to save it as WML for save too.
User avatar
Heindal
Posts: 1344
Joined: August 11th, 2011, 9:25 pm
Location: Germany, Karlsruhe
Contact:

Re: Potential bug in wml.lua

Post by Heindal »

Deactivating it will end in a sudden defeat? What does this thing? After all, everything is working fine, until I try to store the unit.
The unit has to recognized by the game, but not by the lua script.

After many tries and bitter tears cried in a dark corner I think I found a solution.

This is the definition of the hero and the "difficulty-based" character:

Code: Select all


[side]
id=you
name= _ "You"
canrecruit=yes
side=1
shroud=yes
fog=yes
team_name=prisonpeace
x=$herox
y=$heroy
controller=human
gold=0
income=-2

#ifdef NIGHTMARE
type=Thughero
#endif

#ifdef HARD
type=Footpadhero
#endif

#ifdef EASY
type=Thiefhero
#endif
[/side]

It seems that his part has to be present in every scenario, otherwise the lua script won`t understand the type of the unit.
At least when you store it. I will try to fix the same thing in Five Fates. Hopefully it works.

Code: Select all

#ifdef NIGHTMARE
type=Thughero
#endif

#ifdef HARD
type=Footpadhero
#endif

#ifdef EASY
type=Thiefhero
#endif
The future belongs to those, who believe in the beauty of their dreams.
Developer of: Trapped, Five Fates, Strange Legacy, Epical, UR Epic Era
Dungeonmasters of Wesnoth, Wild Peasants vs Devouring Corpses, Dwarf Dwarfson Dwarvenminer
User avatar
Heindal
Posts: 1344
Joined: August 11th, 2011, 9:25 pm
Location: Germany, Karlsruhe
Contact:

Re: Potential bug in wml.lua

Post by Heindal »

And the problem is there again, after restarted it today and changed a little bit of the code (not the code I believed to cause the problem, but added some new options). Seems like a problem I can't solve.
The future belongs to those, who believe in the beauty of their dreams.
Developer of: Trapped, Five Fates, Strange Legacy, Epical, UR Epic Era
Dungeonmasters of Wesnoth, Wild Peasants vs Devouring Corpses, Dwarf Dwarfson Dwarvenminer
User avatar
Heindal
Posts: 1344
Joined: August 11th, 2011, 9:25 pm
Location: Germany, Karlsruhe
Contact:

Re: Potential bug in wml.lua

Post by Heindal »

Leveling up a unit effected by this bug will cause this to happen:

Code: Select all

20220130 13:47:11 error scripting/lua: bad argument #3 to '?' (WML table expected, got table)
stack traceback:
	[C]: in ?
20220130 13:47:11 error scripting/lua: bad argument #3 to '?' (WML table expected, got table)
stack traceback:
	[C]: in ?
20220130 13:47:11 error scripting/lua: Effect __descr metafunction should have returned a string, but instead returned 20220130 13:47:11 error scripting/lua: table
However leveling up the unit seems to be no problem at all and works. In that moment you can no longer save games, because it is considered as corrupted.
The future belongs to those, who believe in the beauty of their dreams.
Developer of: Trapped, Five Fates, Strange Legacy, Epical, UR Epic Era
Dungeonmasters of Wesnoth, Wild Peasants vs Devouring Corpses, Dwarf Dwarfson Dwarvenminer
User avatar
Heindal
Posts: 1344
Joined: August 11th, 2011, 9:25 pm
Location: Germany, Karlsruhe
Contact:

Re: Potential bug in wml.lua

Post by Heindal »

I found the solution and the reason for the bugs. I found it in the log a while ago, but as the wording seemed to be like: Hey, we just ignore this deprecated code, I did not believe that this was the reason.

The defense of some units still had some false parameters:

deep water should be deep_water
shallow water should be shallow_water
mushroom grove should be fungus
coastal reef should be reef


While this makes sense, as an id should not contain spaces, it was accepted in the past.
The log clearly says it is an error, but allows these wrong defense parameters and says it ignores them!

The lua code will probably read the wrong defense and sees two variable (deep water) instead of one (deep_water).
The behavior of the game is strange however and you should think about, not to allow the start of an add-on with the wrong parameters, maybe giving an advice not to use spaces in the defense definitions.
The future belongs to those, who believe in the beauty of their dreams.
Developer of: Trapped, Five Fates, Strange Legacy, Epical, UR Epic Era
Dungeonmasters of Wesnoth, Wild Peasants vs Devouring Corpses, Dwarf Dwarfson Dwarvenminer
Post Reply