Potential bug in wml.lua
Moderator: Forum Moderators
Forum rules
Before reporting issues in this section, you must read the following topic:
Before reporting issues in this section, you must read the following topic:
Potential bug in wml.lua
Currently I'm receiving this odd bug in one of my campaigns:
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.
It is triggered when I use [store_unit]. E.g.:
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.
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>
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
})
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 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
Developer of: Trapped, Five Fates, Strange Legacy, Epical, UR Epic Era
Dungeonmasters of Wesnoth, Wild Peasants vs Devouring Corpses, Dwarf Dwarfson Dwarvenminer
Re: Potential bug in wml.lua
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.
Re: Potential bug in wml.lua
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.
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
Developer of: Trapped, Five Fates, Strange Legacy, Epical, UR Epic Era
Dungeonmasters of Wesnoth, Wild Peasants vs Devouring Corpses, Dwarf Dwarfson Dwarvenminer
Re: Potential bug in wml.lua
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.
Re: Potential bug in wml.lua
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:
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.
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]
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
Developer of: Trapped, Five Fates, Strange Legacy, Epical, UR Epic Era
Dungeonmasters of Wesnoth, Wild Peasants vs Devouring Corpses, Dwarf Dwarfson Dwarvenminer
Re: Potential bug in wml.lua
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
Developer of: Trapped, Five Fates, Strange Legacy, Epical, UR Epic Era
Dungeonmasters of Wesnoth, Wild Peasants vs Devouring Corpses, Dwarf Dwarfson Dwarvenminer
Re: Potential bug in wml.lua
Leveling up a unit effected by this bug will cause this to happen:
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.
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
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
Developer of: Trapped, Five Fates, Strange Legacy, Epical, UR Epic Era
Dungeonmasters of Wesnoth, Wild Peasants vs Devouring Corpses, Dwarf Dwarfson Dwarvenminer
Re: Potential bug in wml.lua
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 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
Developer of: Trapped, Five Fates, Strange Legacy, Epical, UR Epic Era
Dungeonmasters of Wesnoth, Wild Peasants vs Devouring Corpses, Dwarf Dwarfson Dwarvenminer