[solved] Updating side variables from LUA script.
Moderator: Forum Moderators
[solved] Updating side variables from LUA script.
In Wesnoth 1.18.2, in my scenario WML, for some sides I have the following variables section:
When I'm trying to access these variable from a LUA script, this seems to work, although not exactly like the documentation describes it. https://wiki.wesnoth.org/VariablesWML#T ... les.5D_tag states that:
,
I get:
I believe this is the right representation of the variables' WML, but reading the documentation I was expecting to get:
If the output of the query is correct, I believe the documentation should be made more clear on what user should expect.
The real problem, however, is that I cannot find a way to update any of the variables (either from LUA console or through a script). The values seem to be read-only for LUA. I can update them the deprecated way, using wesnoth.set_side_variable function, in which case the array seems to be addressed like the documentation describes, i.e. I can access the first tactic's counter with "tactics.tactic[0].count".
So to sum up, the new way of accessing these variables seems to either be buggy or insufficiently documented. Can someone shed some light on the matter, please?
Code: Select all
[variables]
[tactics]
[tactic]
role=assassin
count=0
weigth=3
[/tactic]
[tactic]
role=hunter
count=0
weight=2
[/tactic]
[tactic] # no particular role
count=0
weight=1
[/tactic]
total_counts=0
total_weights=6
[/tactics]
[/variables]
[/tactics]
However, when I access:An array variable with given name foo is assigned using several [foo] tags, where the first tag describes foo[0], the second foo[1], ...
Code: Select all
wesnoth.sides[4].variables.tactics
I get:
Code: Select all
{{'tactic', {role='assassin',count=0,weight=3}},{'tactic', {role=hunter,count=0,weight=2}},{'tactic',{weight=1,count=0}},total_counts=0,total_weights=6}
Code: Select all
{{role='assassin',count=0,weight=3},{role=hunter,count=0,weight=2},{count=0,weight=1}}
The real problem, however, is that I cannot find a way to update any of the variables (either from LUA console or through a script). The values seem to be read-only for LUA. I can update them the deprecated way, using wesnoth.set_side_variable function, in which case the array seems to be addressed like the documentation describes, i.e. I can access the first tactic's counter with "tactics.tactic[0].count".
So to sum up, the new way of accessing these variables seems to either be buggy or insufficiently documented. Can someone shed some light on the matter, please?
Last edited by Sventimir on July 23rd, 2024, 2:23 pm, edited 1 time in total.
- Celtic_Minstrel
- Developer
- Posts: 2371
- Joined: August 3rd, 2012, 11:26 pm
- Location: Canada
- Contact:
Re: Updating side variables from LUA script.
The new way of accessing them is documented on the wiki here. You can also use the functions in the
For example:
wml
module on them now, which wasn't possible with the old way.For example:
Code: Select all
local my_side = wesnoth.sides[1]
print(my_side.variables["tactics.tactic[0]"])
-- prints {role = "assassin", count = 0, weight = 3}
print(wml.array_access.get("tactics", my_side))
-- prints {{role='assassin',count=0,weight=3},{role=hunter,count=0,weight=2},{count=0,weight=1}}
Re: Updating side variables from LUA script.
Thanks for the pointer, I think I've figured it out now.