enclave's Lua thread
Moderator: Forum Moderators
Re: enclave's Lua thread
Regarding Lua,
are local lua variables stored "only" on each separate client?
I mean if I assign
then each player can work with it, access, modify...
for each player $variable would be same (25) unless somebody change it.
but if I do
is it only available on each separate client, and they can not access each other's arrays or variables? So each client potentialy could have same local variable with different value? for example for player 1 lua variable=25, player 2 same name lua variable=20, player 3 variable=67 ? And they can not share it, access, modify.. ?
Thank you!
are local lua variables stored "only" on each separate client?
I mean if I assign
Code: Select all
{VARIABLE variable 25}
for each player $variable would be same (25) unless somebody change it.
but if I do
Code: Select all
local variable = 25
Thank you!
Re: enclave's Lua thread
There is a known bug in in 1.12.1 and older version that can casue this OOS. Make sure all players have version 1.12.2. Otherwise this can of course also happen because of unsafe wml code.enclave wrote: I'm observing replay of a game of my mod..
The players got OOS in turn 1.. and again i see "calculated movement destination (x=39 y=7) didn't match the original destination (x=38 y=7)".. Why could it be?
Yes prestart is synced.enclave wrote: is prestart synced?
No things inside sync_choice will only happen in one client. meaning everything inside sync_choice is unsynced so modiifying teh gamestate there (for example with [unit]) will cause OOS, this is also explained in the wiki page about OOS.enclave wrote: my placement of [unit] units is happening in prestart event.. should i put it with synchronized choice or move it to turn 1 or leaving it as is is safe? Any advices very much appreciated, thank you!!!
You don't write it anywhere, its just for people who want to anylyze replay saves with a text editor. (or it ca explain some OOS messages where teh OOS message sais somethign like "... not found, found indead: <wmlcode>")enclave wrote: PPS. how to use this http://wiki.wesnoth.org/ReplayWML ??? where to put it? why? any information would help thanks!
[/quote]enclave wrote: PPPS. the latest bug I just got is: some OOSes.. and then I was offered to recruit a unit in a saved replay game.. ??? wth.. I was also able to recruit, but the units were becoming different color (becoming previous side's ownership on current side territory.. or similar.. hard to understand) and was given hell lot of other options, please check attachment for replay.. I think it is because by mistake they gave control to non-existing side in this particular case.. was 7 players, they gave observer control of side 8.. So i guess this particular replay is not bugged by code.. but by user's actions.. in the end of replay blue's units were in 4 different parts of world..
I assume by recruit you mean custom recuit that way implemented in wml/lua with [message][option]? In case of an OOS it can sometimes happen that teh game does not know which [option] was selected by the player. In this case teh game promts the [message] to the replay viewer hopin that he knows which [option] was selected.
No except that the lua variable is local is both the same. In both cases the variable is store in each client seperately and should be the same on all clients if you write safe code.enclave wrote:Regarding Lua,
are local lua variables stored "only" on each separate client?
I mean if I assignthen each player can work with it, access, modify...Code: Select all
{VARIABLE variable 25}
for each player $variable would be same (25) unless somebody change it.
but if I dois it only available on each separate client, and they can not access each other's arrays or variables? So each client potentialy could have same local variable with different value? for example for player 1 lua variable=25, player 2 same name lua variable=20, player 3 variable=67 ? And they can not share it, access, modify.. ?Code: Select all
local variable = 25
Thank you!
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
Thank you gfgtdf for all the answers!
This one i didn't understand using sync_choice with [unit] would cause OOS?gfgtdf wrote:No things inside sync_choice will only happen in one client. meaning everything inside sync_choice is unsynced so modiifying teh gamestate there (for example with [unit]) will cause OOS, this is also explained in the wiki page about OOS.enclave wrote: my placement of [unit] units is happening in prestart event.. should i put it with synchronized choice or move it to turn 1 or leaving it as is is safe? Any advices very much appreciated, thank you!!!
Re: enclave's Lua thread
You shall not change the gamestate in the function you pass to sync_choice (this usually imples using [unit]) this is explained here http://wiki.wesnoth.org/OOS_%28Out_of_Sync%29 and here http://wiki.wesnoth.org/LuaWML:Misc#wes ... ize_choice.enclave wrote: This one i didn't understand using sync_choice with [unit] would cause OOS?
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, I will read it!;)
Re: enclave's Lua thread
Hello!
1) Anyone knows a lua way to react to the keyboard input? something like OnKeyPress("h") do hablabla()
2) Anyone knows a lua way to react on opening right click menu and selecting "terrain description"?
for example...
Thanks!
1) Anyone knows a lua way to react to the keyboard input? something like OnKeyPress("h") do hablabla()
2) Anyone knows a lua way to react on opening right click menu and selecting "terrain description"?
for example...
Code: Select all
function wesnoth.game_events.on_event()
if wesnoth.current.event_context.name == "RC_Options_terrain_description" then
hablabla()
end
end
- Elvish_Hunter
- Posts: 1576
- Joined: September 4th, 2009, 2:39 pm
- Location: Lintanir Forest...
Re: enclave's Lua thread
There isn't any that I'm aware of, sorry. The only keyboard bindings available (which cannot be modified) when using GUI2/Lua stuff are Enter and Esc, which will both close a dialog and return two different values.enclave wrote:1) Anyone knows a lua way to react to the keyboard input? something like OnKeyPress("h") do hablabla()
Both wesnoth.game_on_event() and wesnoth.current.event_context refer to WML events, not to GUI events. Given this fact, you can actually use something like this to fire a "RC_Options_terrain_description" event:enclave wrote:2) Anyone knows a lua way to react on opening right click menu and selecting "terrain description"?Code: Select all
function wesnoth.game_events.on_event() if wesnoth.current.event_context.name == "RC_Options_terrain_description" then
Code: Select all
[set_menu_item]
id=terrain_description
description= _ "Terrain description"
[command]
[fire_event]
name=RC_Options_terrain_description
[/fire_event]
[/command]
[/set_menu_item]
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
wml menu items are implemented by generating a event form the content of the [command] where teh name is "menu item <menu_item_id>" (in 1.13 the spaces were changes to underscores to its "menu_item_<menu_item_id>")
so in the code form EH this code:
coudl also be used to detect the menu item click
so in the code form EH this code:
Code: Select all
if wesnoth.current.event_context.name == "menu item terrain_description" then ... end
You can specify default hotkeys in [set_menu_item].enclave wrote: 1) Anyone knows a lua way to react to the keyboard input? something like OnKeyPress("h") do hablabla()
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
Wow, Thank you both Elvish_Hunter and gfgtdf, you both gave me some information and I will try it soon and let you know what worked for me and what didn't..
but I don't know if it is C++ coded or it can be changed with lua or wml..
My goal is to try to make an unsynchronized menu... (which works in 1.12 when it is not your turn) that would react to key press instead of mouse manipulations..
to replace this:
One of my ideas was to replace it with just openening "terrain description" instead.. if it is possible.. who would need to read terrain description anyway?...
This is unfortunately not what I am looking for.. I need something stronger.. like "n" key that you use to circle through units..You can specify default hotkeys in [set_menu_item].
but I don't know if it is C++ coded or it can be changed with lua or wml..
My goal is to try to make an unsynchronized menu... (which works in 1.12 when it is not your turn) that would react to key press instead of mouse manipulations..
to replace this:
Code: Select all
local last_mouse_over_time
local mouseover_counter = 0
function wesnoth.game_events.on_event()
--test_new_lua_things()
if wesnoth.current.event_context.name == "select" then
local time = wesnoth.get_time_stamp()
if last_mouse_over_time and ((time - last_mouse_over_time) > 2000) then
mouseover_counter = 0
unit1_moused_over_x = nil; unit1_moused_over_y = nil
unit2_moused_over_x = nil; unit2_moused_over_y = nil
end
last_mouse_over_time = time
local du = wesnoth.get_displayed_unit()
if du then
if (du.x == unit2_moused_over_x) and (du.y == unit2_moused_over_y) then
mouseover_counter = mouseover_counter + 1
unit1_moused_over_x = unit2_moused_over_x
unit1_moused_over_y = unit2_moused_over_y
unit2_moused_over_x = du.x
unit2_moused_over_y = du.y
if mouseover_counter > 2 then
mouseover_counter = 0
wesnoth.fire_event("show_unsynced_menu")
end
else
-- think here, mouseover_counter = 0
unit2_moused_over_x = du.x
unit2_moused_over_y = du.y
end
end
end
end
Re: enclave's Lua thread
in wesnoth 1.13 you cna just add unsyced=yes to [set_menu_item] which can be used liek this (also together with defualt_hotkey) which is then also avaialbe in ememy turn.
No, all default hotkeys like show help or cycle units are coded in c++ and the only way to to add hotkeys from wml/lua is default_hotkey from [set_menu_item].
What you could do it tracking the mouse movement (when mouse enters hexes) with wesnoth.theme_items and use that to make your code react to some mouse gestures, but i wound't call that easy.
No, all default hotkeys like show help or cycle units are coded in c++ and the only way to to add hotkeys from wml/lua is default_hotkey from [set_menu_item].
What you could do it tracking the mouse movement (when mouse enters hexes) with wesnoth.theme_items and use that to make your code react to some mouse gestures, but i wound't call that easy.
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
Actually, this time reading through the reference of wesnoth.theme_items I started to understand something. Though I am quite content with the solution I managed to get, this way it isnt immediately obvious that its from EoHS.What you could do it tracking the mouse movement (when mouse enters hexes) with wesnoth.theme_items and use that to make your code react to some mouse gestures, but i wound't call that easy.
Btw, does the 1.13 standard unsynced menu provide way to see who opened it? Given that side_number wont be reliable anymore. (unsynced key isnt documented in wiki currently)
Re: enclave's Lua thread
Yes afaik 1.13 has a lua function to query the viewing side wesnoth.get_vewing_side() see the definition here: https://github.com/wesnoth/wesnoth/blob ... l.cpp#L664 this was introduced in wesnoth 1.13.1.Ravana wrote: Btw, does the 1.13 standard unsynced menu provide way to see who opened it? Given that side_number wont be reliable anymore. (unsynced key isnt documented in wiki currently)
Also note the such unsynced meanus could also be used from observers.
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
Nice! I didnt really expect that much. That was my main motivation for working with select-based menu.Also note the such unsynced meanus could also be used from observers.
Re: enclave's Lua thread
Thanks very much for information gfgtdf! if no other tricks work i will think about just selecting some specific tile on map.. may help:)
I just came across some simple task.. And it will take me ages to find it in help, so maybe if I ask you would know..
I done this:
I need them to have name, because so people know their starting positions on map..
Now i just want all names on prestart to be renamed to normal..
because my settings made all leader names be "Portugal" and others.. And I just tried to access original names and I can not do it with WML.. nothing works.. i did [store_side] and then tried to access name, team_name, user_team_name, current_player
everything gives me either Portugal, or nil.. but in the status table I can see original names.. so they must be somewhere,
accessable.. somehow... but how? is there a quick lua way?
Thanks very much in advance!
I just came across some simple task.. And it will take me ages to find it in help, so maybe if I ask you would know..
I done this:
Code: Select all
[side]
side=1
team_name=Portugal
color=red
canrecruit=yes
controller=human
name=Portugal
...
Now i just want all names on prestart to be renamed to normal..
because my settings made all leader names be "Portugal" and others.. And I just tried to access original names and I can not do it with WML.. nothing works.. i did [store_side] and then tried to access name, team_name, user_team_name, current_player
everything gives me either Portugal, or nil.. but in the status table I can see original names.. so they must be somewhere,
accessable.. somehow... but how? is there a quick lua way?
Thanks very much in advance!
Re: enclave's Lua thread
hmm i dont really understand what do you maen by 'original names' ?
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.