enclave's Lua thread
Moderator: Forum Moderators
Re: enclave's Lua thread
http://prntscr.com/71v0g9
Does this OOS mean I need to use synchronized choice?
I guess I will find bug before you reply, but just in case.. maybe somebody online and will answer now.. thanks!
The other one is saying this:
[input] expected but none found
. found instead:
dependent = yes
from_side = server
sent = yes
[random_seed]
new_seed = 1550863692
[/random_seed]
if yes then what would be the event? any ideas?
Does this OOS mean I need to use synchronized choice?
I guess I will find bug before you reply, but just in case.. maybe somebody online and will answer now.. thanks!
The other one is saying this:
[input] expected but none found
. found instead:
dependent = yes
from_side = server
sent = yes
[random_seed]
new_seed = 1550863692
[/random_seed]
if yes then what would be the event? any ideas?
- Elvish_Hunter
- Posts: 1575
- Joined: September 4th, 2009, 2:39 pm
- Location: Lintanir Forest...
Re: enclave's Lua thread
Yes, you do. GUI/Lua dialogs aren't synchronized, and at least the postshow() function needs to be wrapped in wesnoth.synchronize_choice(). This applies for campaigns as well, because you may end up corrupting the replay otherwise.enclave wrote:Does this OOS mean I need to use synchronized choice?
If you want some examples about how to use it, you can check the gui-tags.lua file in the Wesnoth Lua Pack.
Current maintainer of these add-ons, all on 1.16:
The Sojournings of Grog, Children of Dragons, A Rough Life, Wesnoth Lua Pack, The White Troll (co-author)
The Sojournings of Grog, Children of Dragons, A Rough Life, Wesnoth Lua Pack, The White Troll (co-author)
Re: enclave's Lua thread
Hi Elvish_Hunter, nice that you are here!
I found the differences in inspector..
In my code i am relying to side.controller...
but using debug inspector I found that p1 (host) has variable of side 3 (AI) controller="ai"
but p2 (network player) has variable of side 3 (AI) as controller="network_ai"
could this cause synchronize problems? if code is something like:
[if] side.controller="ai" then ........
so it works on host machine, but for network players it gives "else" because side.controller="network_ai"....
i wonder?
I found the differences in inspector..
In my code i am relying to side.controller...
but using debug inspector I found that p1 (host) has variable of side 3 (AI) controller="ai"
but p2 (network player) has variable of side 3 (AI) as controller="network_ai"
could this cause synchronize problems? if code is something like:
[if] side.controller="ai" then ........
so it works on host machine, but for network players it gives "else" because side.controller="network_ai"....
i wonder?
Re: enclave's Lua thread
enclave:
Yes, side.controller is generally "unsafe" unless you are careful as gfgtdf describes. I think there are notes to the effect on the wiki.
These are basically warts in how the engine is designed.
A different way to design it would be like "controller_machine" being a pointer / id type of what machine is controlling the side, and "controller_type" beng like "human | ai | null" and then it can be the same on all machines. But it adds complexity that has to be dealt with when saving / reloading the game, and adds a bunch of data that's not very intelligible to the save files.
So instead, we just don't guarantee that each machine really knows what machine controls each side. It only knows "do I control it or does another machine control it", and the server is supposed to handle the details.
Other sorts of wrinkles I would expect would have to do with translation. I'm not sure for instance if unit names are different when you play in French vs. in Russian? If so then they are also unsafe, and code like
would likely cause OOS.
Edit: Here's a more concrete example:
Assuming that "wesnoth-foo" is the text domain of your add-on, if you have "one" translated as "uno" in one language, but not in another, it would probably cause OOS if you played a game, then changed langauges and tried to watch the replay, or if you tried to have a game between a spanish person and non-spanish.
Yes, side.controller is generally "unsafe" unless you are careful as gfgtdf describes. I think there are notes to the effect on the wiki.
These are basically warts in how the engine is designed.
A different way to design it would be like "controller_machine" being a pointer / id type of what machine is controlling the side, and "controller_type" beng like "human | ai | null" and then it can be the same on all machines. But it adds complexity that has to be dealt with when saving / reloading the game, and adds a bunch of data that's not very intelligible to the save files.
So instead, we just don't guarantee that each machine really knows what machine controls each side. It only knows "do I control it or does another machine control it", and the server is supposed to handle the details.
Other sorts of wrinkles I would expect would have to do with translation. I'm not sure for instance if unit names are different when you play in French vs. in Russian? If so then they are also unsafe, and code like
Code: Select all
u = ... some filter ...
if u.name == "Anabel" then
wesnoth.message("Our savior has arrived!")
wesnoth.action_wml.gold({side = u.side, gold=1000})
end
Edit: Here's a more concrete example:
Code: Select all
_ = wesnoth.textdomain("wesnoth-foo")
if _("one") == "uno" then
wesnoth.action_wml.gold({side = 1, gold = 1000})
end
Re: enclave's Lua thread
thx everyone, solved my OOS, it was indeed controller problem..
Im surprized that I didnt need synchronized choice,
solved problem like this:
[if]
[variable]
name=za_sides[$player_setup].controller
equals=ai
[/variable]
[or]
[variable]
name=za_sides[$player_setup].controller
equals=network_ai
[/variable]
[/or]
[then]
{VARIABLE player[$player_setup].zombie "ON"}
{SURVIVAL_ZA_STARTING_POSITIONS}
[modify_side]
side=$player_setup
[ai]
aggression=1.0
[/ai]
[/modify_side]
[/then]
[else]
{VARIABLE player[$player_setup].zombie "OFF"}
[/else]
[/if]
(za_sides is an array, which is created like this before:
)
so all clients come into same variable no matter what they see "ai" or "network_ai"
no more OOS, tested.
Thanks everyone for help!
Im surprized that I didnt need synchronized choice,
solved problem like this:
[if]
[variable]
name=za_sides[$player_setup].controller
equals=ai
[/variable]
[or]
[variable]
name=za_sides[$player_setup].controller
equals=network_ai
[/variable]
[/or]
[then]
{VARIABLE player[$player_setup].zombie "ON"}
{SURVIVAL_ZA_STARTING_POSITIONS}
[modify_side]
side=$player_setup
[ai]
aggression=1.0
[/ai]
[/modify_side]
[/then]
[else]
{VARIABLE player[$player_setup].zombie "OFF"}
[/else]
[/if]
(za_sides is an array, which is created like this before:
Code: Select all
#define SURVIVAL_ZA_PRESTART
[store_side]
variable=tmp_za_sides
[/store_side]
##
{FOREACH tmp_za_sides i}
{VARIABLE za_sides[$tmp_za_sides[$i].side].controller $tmp_za_sides[$i].controller}
{NEXT i}
#enddef
so all clients come into same variable no matter what they see "ai" or "network_ai"
no more OOS, tested.
Thanks everyone for help!
Re: enclave's Lua thread
Yes, the sync choice in http://forums.wesnoth.org/viewtopic.php?f=21&t=41347 is not really needed, however there were (are?) some bugs in wesnoth that could result in having differnt controller values in differnt clients (human in one and ai on the other). Those usually only appear in more compicated situations for example when a player left and the controller was assigned to ai and then soneone was trying to replay the mp game from the savefile. So i think it better to preventative guard against such situation with wesnoth.synchonize_choice
Scenario with Robots SP scenario (1.11/1.12), allows you to build your units with components, PYR No preperation turn 1.12 mp-mod that allows you to select your units immideately after the game begins.
Re: enclave's Lua thread
thx gfgtdf, very true.. and good to know.. now i understand where all the bugs were coming from with passing control from one player to another.. in the past versions..
in my case this code only happens in the beginning.. so no players expected to leave.. so I guess in my particular scenario im safe.. but still very useful information for everyone.
in my case this code only happens in the beginning.. so no players expected to leave.. so I guess in my particular scenario im safe.. but still very useful information for everyone.
Re: enclave's Lua thread
Anyone knows if rand is safe to use without synchronization?
I need to use random units spawn from a list of units.. need to know the safest way to use it without having problems..
was it math the non-safe one?
I need to use random units spawn from a list of units.. need to know the safest way to use it without having problems..
was it math the non-safe one?
Re: enclave's Lua thread
I spawn units with
So yes, wml way of random.
Code: Select all
... more lists
level_four = {"AE Aragwaithi Ancient Banner","AE Avian Diamondbeak","AE Celestial Seraph","AE Ceresian Metropolitan","AE Chaos Overlord","AE_mag_Darkblood_Chosen_of_Forest","AE Cult Inhuman","AE Cult Primordial","AE Desert Star","AE Dwarvish Arcanister","AE Eltirean Sky Lord","AE Eltirean Whirlpool Lord","AE Emperor_s Guard Daimyo","AE Enchanter Apacalyptic","AE Enchanter Excalibur","AE Enchanter Rune Master","AE_mag_Sky_Kingdom_Guru","AE_mag_Sky_Kingdom_Master_of_Elements","AE Garou","AE Hierarch of Aten","AE High Council Elder","AE Highlander Odin","AE Infernai Lucifer","AE_mag_Al_Kamija_Mystic_Jinn","AE Judgement","AE khalid","AE_mag_Kharos_Kirios","AE_mag_Kharos_Master_of_Sun","AE Legatus","AE Leviathan","AE Librarian","AE Methusalem","AE Patriarch","AE Saurian Ice Lord","AE_mag_Al_Kamija_Summons_Master","AE_mag_Tharis_Master_of_Darkness","AE_mag_Tharis_Master_of_War","AE_agl_frozen_ice_golem_titan","AE_arc_khthon_Khalkotaurus","AE_arc_phantom_Mummy_Pharo","AE_arc_primeval_Titan","AE_arc_ukians_Ukian_Commander","AE_imp_Sidhe_Dark_Thunderblade","AE_imp_Sidhe_Stormlord","AE_mag_Barbarians_Barbarian_King","AE_mag_Barbarians_Cyclops_Destroyer","AE_mag_Destroyers_Abaddon","AE_mag_Destroyers_Moloch","AE_mag_Runemasters_Dwarvish_Rune_Lord","AE_mag_Runemasters_Runemaster","AE_Primeval Sunwheel","AE_Steelhive_Hive_Empress","AE_StormQueen"}
function randomUnit(level,x,y,side)
wesnoth.fire("set_variable", { name = "LUA_random", rand = string.format("%d..%d", 1, #level) })
local unitid = level[wesnoth.get_variable "LUA_random"]
wesnoth.set_variable "LUA_random"
wesnoth.fire("unit", { type = unitid, placement = map_passable, x = x, y = y, side = side })
wesnoth.fire("set_variable", { name = "last_unit", value = unitid })
end
Re: enclave's Lua thread
Thanks Ravana.. simple code, but I can't even understand it yet all I understood, you used rand, so I guess that's the safe way:)
I was watching replay of one of my era games (reload of previously corrupted OOS game, where one of users had Mac and I guess in his view controller of AI side is neither "ai" nor "network_ai", no idea..), and I had out of sync error like this after reload:
[random_seed] expected but none found, found instead:
sent =
[move]
x=9,10,11
y=3,3,4
[/move]
[checkup]
[result]
final_hex_x=11
final_hex_y=4
stopped_early = no
[/result]
[result]
random_calls=0
[/result]
[/checkup]
1) any ideas what it may be? my knowledge too poor, I will never find this bug without help..
Funny thing, they kept playing, so OOS is only for replay..
2) And the next error was again "found dependent command in replay while is_synced=false"
again no idea what it is either.. because other games I observed with same version of my mod didnt have any OOS at all..
What I see different is there are no villages where they should be...
next error:
"calculated movement destination (x=12 y=21) didnt match the original destination(x=13 y=22)"
after some time (around turn 6) after I ignored all errors, the wesnoth just shut down.. but im sure they played till turn 21, thats what it says on replay.. and they never gave a sign of seeing any OOS.
3) I think all my replays from reloads are corrupted by the way, not 100% sure, coz I dont remember..
What do I need to keep in mind for correct replays, what do i need to do in my code?
When we play from reload, never a problem, but replays are corrupted..
thanks to everyone for all your help!
I was watching replay of one of my era games (reload of previously corrupted OOS game, where one of users had Mac and I guess in his view controller of AI side is neither "ai" nor "network_ai", no idea..), and I had out of sync error like this after reload:
[random_seed] expected but none found, found instead:
sent =
[move]
x=9,10,11
y=3,3,4
[/move]
[checkup]
[result]
final_hex_x=11
final_hex_y=4
stopped_early = no
[/result]
[result]
random_calls=0
[/result]
[/checkup]
1) any ideas what it may be? my knowledge too poor, I will never find this bug without help..
Funny thing, they kept playing, so OOS is only for replay..
2) And the next error was again "found dependent command in replay while is_synced=false"
again no idea what it is either.. because other games I observed with same version of my mod didnt have any OOS at all..
What I see different is there are no villages where they should be...
next error:
"calculated movement destination (x=12 y=21) didnt match the original destination(x=13 y=22)"
after some time (around turn 6) after I ignored all errors, the wesnoth just shut down.. but im sure they played till turn 21, thats what it says on replay.. and they never gave a sign of seeing any OOS.
3) I think all my replays from reloads are corrupted by the way, not 100% sure, coz I dont remember..
What do I need to keep in mind for correct replays, what do i need to do in my code?
When we play from reload, never a problem, but replays are corrupted..
thanks to everyone for all your help!
Re: enclave's Lua thread
in wesnoth 1.12 there is a helper.rand() function for safe random numbers.enclave wrote:Thanks Ravana.. simple code, but I can't even understand it yet all I understood, you used rand, so I guess that's the safe way:)
This means the action before the move from (9,3) to (11,4) invoked an event and while your replay client calculated thata random number is needed, the original client calculated that no random number is needed.enclave wrote: I was watching replay of one of my era games (reload of previously corrupted OOS game, where one of users had Mac and I guess in his view controller of AI side is neither "ai" nor "network_ai", no idea..), and I had out of sync error like this after reload:
[random_seed] expected but none found, found instead:
sent =
[move]
x=9,10,11
y=3,3,4
[/move]
[checkup]
[result]
final_hex_x=11
final_hex_y=4
stopped_early = no
[/result]
[result]
random_calls=0
[/result]
[/checkup]
1) any ideas what it may be? my knowledge too poor, I will never find this bug without help..
Funny thing, they kept playing, so OOS is only for replay..
So you say the map has changed? I dont know how why that happens.enclave wrote:
2) And the next error was again "found dependent command in replay while is_synced=false"
again no idea what it is either.. because other games I observed with same version of my mod didnt have any OOS at all..
What I see different is there are no villages where they should be...
Later OOS error are often caused by the earlier OOS errors, mreaning it is quiet normal that other OOS appear after continued after an OOS report.enclave wrote:
next error:
"calculated movement destination (x=12 y=21) didnt match the original destination(x=13 y=22)"
Usually wesnoth shouldnt just shut down, you can open a bug report if you want.enclave wrote:
after some time (around turn 6) after I ignored all errors, the wesnoth just shut down.. but im sure they played till turn 21, thats what it says on replay.. and they never gave a sign of seeing any OOS.
If people change sides controller after reloading it can cause OOS in replays, some cases can be solved by wesnoth.sync_choice like i said above. but for example if someone decides to set a side that that was previously plaed by a player to be empty after a reload it will break replays of the game and wml cannot fix this case.enclave wrote:
3) I think all my replays from reloads are corrupted by the way, not 100% sure, coz I dont remember..
What do I need to keep in mind for correct replays, what do i need to do in my code?
When we play from reload, never a problem, but replays are corrupted..
thanks to everyone for all your help!
Scenario with Robots SP scenario (1.11/1.12), allows you to build your units with components, PYR No preperation turn 1.12 mp-mod that allows you to select your units immideately after the game begins.
Re: enclave's Lua thread
thanks gfgtdf, already found the same somehow:) used it, no problems, no OOSes, works wonderful!gfgtdf wrote: in wesnoth 1.12 there is a helper.rand() function for safe random numbers.
any ideas why would other client calculate things different way? what are the most popular causes? I assume if variables were stored in lua, they could get lost after reload..? anything else most popular cause?gfgtdf wrote: This means the action before the move from (9,3) to (11,4) invoked an event and while your replay client calculated thata random number is needed, the original client calculated that no random number is needed.
I take replays from http://replays.wesnoth.org/1.12/ , could that client be out of date (or the opposite (1.13+)) and modify the replay in some way that my client can not read after?
Not the original map, but changes done to it during play:gfgtdf wrote: So you say the map has changed? I dont know how why that happens.
In my add-on peasants can build buildings, so yeah.. if i watch replay consisting of 2 parts.. the first one lets say is ok, no errors.. peasants lets say built 2 villages.. then somebody dc or something else.. they reload, i watch the second part of replay from server.
And villages disappeared, plus different OOSes...
Which way the labels are stored? wml variables or lua? i guess wml.. but still..
yeah, makes sense.. so I better look only for the first 2 errors.. basically..?gfgtdf wrote: Later OOS error are often caused by the earlier OOS errors, mreaning it is quiet normal that other OOS appear after continued after an OOS report.
thanks, will check that..gfgtdf wrote: Usually wesnoth shouldnt just shut down, you can open a bug report if you want.
so in your opinion, if p1 was enclave but then reloaded a game as enclave1 it could cause replay OOS? for example if there is a message with side.name? or its not enough for OOS.. ?gfgtdf wrote: If people change sides controller after reloading it can cause OOS in replays, some cases can be solved by wesnoth.sync_choice like i said above. but for example if someone decides to set a side that that was previously plaed by a player to be empty after a reload it will break replays of the game and wml cannot fix this case.
Thanks very much for hints and information, was very helpful!
Re: enclave's Lua thread
Yes global lua variables are lost when reloading. Thats why it is usually not recommended to store data in global lua variables. It is possible to store data in lau global variables and then write them to wml variables in wesnoth.game_events.on_save and then load them from wml to lua variables in preload events.enclave wrote: any ideas why would other client calculate things different way? what are the most popular causes? I assume if variables were stored in lua, they could get lost after reload..? anything else most popular cause?
I take replays from http://replays.wesnoth.org/1.12/ , could that client be out of date (or the opposite (1.13+)) and modify the replay in some way that my client can not read after?
Most common casues of oos are different add-on versions, or unsafe use of side.controller, wesnoth.game_config.version or similar. Did you read the wiki page http://wiki.wesnoth.org/OOS_%28Out_of_Sync%29 about OOS ?
Labels usually don't casue OOS they just change the diplay but its is afaik not possible to for example change units dependent on current map labels.enclave wrote: Not the original map, but changes done to it during play:
In my add-on peasants can build buildings, so yeah.. if i watch replay consisting of 2 parts.. the first one lets say is ok, no errors.. peasants lets say built 2 villages.. then somebody dc or something else.. they reload, i watch the second part of replay from server.
And villages disappeared, plus different OOSes...
Which way the labels are stored? wml variables or lua? i guess wml.. but still..
Yes, maybe there are some cases where later errors contains more detailed information, but i currently i cannot think of any such case, so giving more than the first 2 or maybe 3 OOS messages usually does not help.enclave wrote: yeah, makes sense.. so I better look only for the first 2 errors.. basically..?
No, what i meant above was changing the controller type of side (human/ai/null) when reloading.enclave wrote: so in your opinion, if p1 was enclave but then reloaded a game as enclave1 it could cause replay OOS? for example if there is a message with side.name? or its not enough for OOS.. ?
Changing the actualy playername can also casue OOS if you use unsave wml (like using side.__cfg.current_player which is unsafe just like side.controller)
Last edited by gfgtdf on May 9th, 2015, 11:44 pm, edited 1 time in total.
Reason: fix a typo
Reason: fix a typo
Scenario with Robots SP scenario (1.11/1.12), allows you to build your units with components, PYR No preperation turn 1.12 mp-mod that allows you to select your units immideately after the game begins.
Re: enclave's Lua thread
thanks very much gfgtdf, im reading now the oos help link you gave, i never read it before I think..