[closed] How wesnoth.set_variable works?
Moderator: Forum Moderators
- ZombieKnight
- Posts: 282
- Joined: June 27th, 2022, 2:26 pm
- Location: Czech Republic
[closed] How wesnoth.set_variable works?
Hi
This code:
gives me this error:
I'm sure wml.variables["my_unit_stored[0].attack[1]"] exists
This code:
Code: Select all
wesnoth.set_variable(wml.variables["my_unit_stored[0].attack[1].damage[0]"],1)
Code: Select all
20240202 14:58:21 info deprecation: wesnoth.set_variable has been deprecated indefinitely.; (Note: You should use wml.variables instead in new code)
20240202 14:58:21 error scripting/lua: lua/core/_initial.lua:50: bad argument #1 to 'elem' (string expected, got nil)
stack traceback:
[C]: in function 'wml.set_variable'
lua/core/_initial.lua:50: in field 'set_variable'
~add-ons/Bandits_from_Brown_Hills/lua/print_data.lua:74: in main chunk
[C]: in field 'dofile'
lua/package.lua:53: in field 'require'
[string "wesnoth.require '~add-ons/Bandits_from_Brown_..."]:1: in local 'bytecode'
lua/wml-tags.lua:265: in local 'cmd'
lua/wml-utils.lua:144: in field 'handle_event_commands'
lua/wml-flow.lua:5: in function <lua/wml-flow.lua:4>
^C
Last edited by ZombieKnight on April 20th, 2024, 6:04 am, edited 1 time in total.
I had saurian in profile before, but I've merged my discord profile with forum one...
Working on campaign Bandits from Brown Hills
Working on campaign Bandits from Brown Hills
- Celtic_Minstrel
- Developer
- Posts: 2290
- Joined: August 3rd, 2012, 11:26 pm
- Location: Canada
- Contact:
Re: How wesnoth.set_variable works?
You seem to be extremely confused here. The syntax
The code you're looking for is this:
However, that won't actually work either, as you can't assign a scalar to a container. You need to add
For what it's worth, if you had been using
wml.variables[...]
and the syntax wesnoth.set_variable
are completely orthogonal; the former replaces the latter.The code you're looking for is this:
Code: Select all
wml.variables["my_unit_stored[0].attack[1].damage[0]"] = 1
.something
onto the end of your variable path, or remove [0]
.For what it's worth, if you had been using
set_variable
, the first parameter would've been just the variable path.