Synchronization with LUA?

Discussion of Lua and LuaWML support, development, and ideas.

Moderator: Forum Moderators

Post Reply
User avatar
PapaSmurfReloaded
Posts: 820
Joined: November 17th, 2007, 1:10 pm
Location: Argentina

Synchronization with LUA?

Post by PapaSmurfReloaded »

Is it possible to synchronize the game all and have all players have the same info as one side in particular, at the end of a set menu item event? :hmm:
gfgtdf
Developer
Posts: 1432
Joined: February 10th, 2013, 2:25 pm

Re: Synchronization with LUA?

Post by gfgtdf »

Not sure what exactly do pi are trying to do, usually wml code menu items (unless they have synced=no) are automatically synced.

Other that that it really depends on what you want trying to do, yes Lua has fundings functions for syncing thing (in particular wesnoth.sync_choice and custom actions) but it cannot break the fundamental game rules (like invoking actions by players other than the current turn's player)
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.
User avatar
PapaSmurfReloaded
Posts: 820
Joined: November 17th, 2007, 1:10 pm
Location: Argentina

Re: Synchronization with LUA?

Post by PapaSmurfReloaded »

ARRPGA has a menu in which one of the sides (The Dungeon Master) can create, modify, delete and move around units at will.
Sometimes, it leads to OOS problems. While checking out LUA I saw that wesnoth.sync_choice exists and I was wondering if it can be used for something along those lines.
User avatar
Ravana
Forum Moderator
Posts: 2949
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: Synchronization with LUA?

Post by Ravana »

When using syncing based on global variables, your use case should be possible with WML - after each action current side asks if master wants to do something.
gfgtdf
Developer
Posts: 1432
Joined: February 10th, 2013, 2:25 pm

Re: Synchronization with LUA?

Post by gfgtdf »

for syncing a specifc variable there is also the [sync_variable] tag. But without knowing where your oos comes from, it will be very hard fixing it. Those tags do not magicially fix any oos error. You have to look the OOS message (like for example 'unfound source of movement' which means that the unit location of that unit was differnt on each client), and then go stepswise backward to find the polace where the OOS orginally happend. Also you always have to consider the posiblity that the oos is not your falut but some other addon that was installed/used on one of the client behaves badly.

A starting point of fixing OOS error is this wiki page https://wiki.wesnoth.org/OOS_(Out_of_Sync) in particular the last part about the list of unsafe functions.
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.
enclave
Posts: 936
Joined: December 15th, 2007, 8:52 am

Re: Synchronization with LUA?

Post by enclave »

PapaSmurfReloaded wrote: January 14th, 2019, 2:18 pm ARRPGA has a menu in which one of the sides (The Dungeon Master) can create, modify, delete and move around units at will.
Sometimes, it leads to OOS problems. While checking out LUA I saw that wesnoth.sync_choice exists and I was wondering if it can be used for something along those lines.
Hi PapaSmurfReloaded, there is lua function like that, the one of the most simple uses would look like this (the example may not work, its partly untested):

Code: Select all

[lua]
code = <<
wesnoth.set_variable("your_variable_name_here",tostring(wesnoth.synchronize_choice(function() return { value = wesnoth.get_variable("your_variable_name_here") } end).value))
>>
[/lua]
this one above would take "your_variable_name_here" WML variable and synchronize it between all players.. i think $side_number would be the side that it is synchronized with.. (the player who's turn it is now)

If you have access to the codes of ARRPGA, look menus for bad functions or events.. and syncronize them by adding synchronization code
for example using lua function math.random(0,5) would create OOS without synchronizing it like below (this example should work, its tested, just missing the WML part):

Code: Select all

[lua]
code = <<
local ns_rand_leader_x = math.random(0,5)
ns_rand_leader_x = wesnoth.synchronize_choice(function() return { value = ns_rand_leader_x } end).value
>>
[/lua]
there may also be OOS events.. when some functions will cause OOS.. i feel i can't express myself correctly, a bit sleepy and headache.. sorry for confusing writing.. basically everything like gfgtdf said.. read about OOS in wiki.. to avoid OOS many criterias should be met:
a) the ARRPGA menus shouldnt be used without syncronization in select/preload events and such (look list of synctonized and non synchronized events here: https://wiki.wesnoth.org/EventWML#Multiplayer_safety)
b) the menus should not have OOS unsafe functions like math.random without synchronization
c) nobody should have add-ons/modifications with conflicting macros or event id's (so for example same menu would have 2 different actions if somebody has conflicting add-on.. i can't list an example, because i'm not sure myself what exactly it would look like, but I always create super unique custom event IDs and macros names.. the basic idea is that for example ARRPGA menu for moving units around would have same ID value as somebody has in 18th century warfare for launching nuclear bomb.. so players who dont have 18th century warfare would see units moved around by dangeon master, but player with 18th century would see the nuke explosion, or not see anything happening at all... so the 18th century guy would now be out of synchronization with the other guys.. OOS happened.. but it's my weak understanding of such conflicts.. it's might be more complicated, or it may have nothing to do with menu IDs, but the general idea is similar to what i wrote above.. although I don't understand how addon that is NOT in use can cause any conflicts... in my opinion it would be an add-on that is IN USE.. but I guess it's not the case..)
User avatar
Ravana
Forum Moderator
Posts: 2949
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: Synchronization with LUA?

Post by Ravana »

Unsynced events can not request synchronization. This is case a).
enclave
Posts: 936
Joined: December 15th, 2007, 8:52 am

Re: Synchronization with LUA?

Post by enclave »

Ravana wrote: January 15th, 2019, 8:04 pm Unsynced events can not request synchronization. This is case a).
if so, there still would be a work around, because in my addon i use select event to highlight enemies and then by right click on one of highlighted targets i can perform ranged attack... in my case select event has [fire_event] in it.. and looks like fired event is already synchronized... so potentially it means that select could trigger the synchronized event menu... [message] or lua table.. so it doesnt even need to be synchronized with lua sync.. ?
User avatar
Ravana
Forum Moderator
Posts: 2949
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: Synchronization with LUA?

Post by Ravana »

Any code called by unsynced event is unsynced. No way to change it.

Best you can do is store the action until synced code wants to use it.
Post Reply