wesnoth.synchronize_selection
Moderator: Forum Moderators
wesnoth.synchronize_selection
This works:
This doesn't work (gives an empty array):
All on Wesnoth 1.10.5, either local or networked multiplayer.
Am I doing something wrong or is synchronize_selection broken?
Code: Select all
helper = wesnoth.require "lua/helper.lua"
function f()
locations = helper.get_variable_array("some_array")
return locations
end
helper.set_variable_array("some_array", f())
Code: Select all
helper = wesnoth.require "lua/helper.lua"
result = wesnoth.synchronize_choice(
function ()
locations = helper.get_variable_array("some_array")
return locations
end
)
helper.set_variable_array("some_array", result)
Am I doing something wrong or is synchronize_selection broken?
- Elvish_Hunter
- Posts: 1575
- Joined: September 4th, 2009, 2:39 pm
- Location: Lintanir Forest...
Re: wesnoth.synchronize_selection
Right now, I don't see anything wrong with the code. Are you attempting to use synchronize_choice in a prestart or start event? If yes, in past I noticed that such function does not work with these two events.
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: wesnoth.synchronize_selection
The code is triggered by a menu item which itself is added in a start event. On an additional note, I could work around the problem by coding the contents of "some_array" into a string and returning a single-field table in the anonymous function.
-
- Inactive Developer
- Posts: 2461
- Joined: August 15th, 2008, 8:46 pm
- Location: Germany
Re: wesnoth.synchronize_selection
synch_choice doesn't work earlier than turn 1, yes.
The return value of the inner function needs to be of type wml table. Yours should be of the form { a, b, c, ... } instead. (For finding out why some table isn't also a wml table, I suggest dbms from the WLP.)
You could use a modified helper function instead
and an analog helper.set_wml_variable_array(var) (untested), so that the form of the passed-through table should be a wml table
{ { "some_array", a }, { "some_array", b }, ... }
where a, b and so on are the assumed wml tables representing a single element/container in the wml variable array some_array.
The return value of the inner function needs to be of type wml table. Yours should be of the form { a, b, c, ... } instead. (For finding out why some table isn't also a wml table, I suggest dbms from the WLP.)
You could use a modified helper function instead
Code: Select all
function helper.get_wml_variable_array(var)
local result = {}
for i = 1, wesnoth.get_variable(var .. ".length") do
table. insert(result, { var, wesnoth.get_variable(string.format("%s[%d]", var, i - 1)) })
end
return result
end
{ { "some_array", a }, { "some_array", b }, ... }
where a, b and so on are the assumed wml tables representing a single element/container in the wml variable array some_array.
projects (BfW 1.12):
A Simple Campaign: campaign draft for wml starters • Plan Your Advancements: mp mod
The Earth's Gut: sp campaign • Settlers of Wesnoth: mp scenario • Wesnoth Lua Pack: lua tags and utils
updated to 1.8 and handed over: A Gryphon's Tale: sp campaign
A Simple Campaign: campaign draft for wml starters • Plan Your Advancements: mp mod
The Earth's Gut: sp campaign • Settlers of Wesnoth: mp scenario • Wesnoth Lua Pack: lua tags and utils
updated to 1.8 and handed over: A Gryphon's Tale: sp campaign
Re: wesnoth.synchronize_selection
Ah-ha! I see now. Thankies.