[~solved] Global_variables with Lua
Moderator: Forum Moderators
- ZombieKnight
- Posts: 337
- Joined: June 27th, 2022, 2:26 pm
- Location: Czech Republic
[~solved] Global_variables with Lua
Hi,
Any idea how to store Lua variable into global_variables?
Once I'll get wml stored into global variable...
How (in event/function) replace wml of scenario with wml from global variable?
Any idea how to store Lua variable into global_variables?
Once I'll get wml stored into global variable...
How (in event/function) replace wml of scenario with wml from global variable?
Last edited by ZombieKnight on May 16th, 2024, 7:20 am, edited 1 time in total.
- Celtic_Minstrel
- Developer
- Posts: 2340
- Joined: August 3rd, 2012, 11:26 pm
- Location: Canada
- Contact:
Re: Global_variables with Lua
The Lua API to global variables is not finalized, so it might change without warning, but it does exist.
That's all equivalent to using the WML tags with
Code: Select all
local GV = wesnoth.experimental.wml.global_vars
local ns = "your_namespace"
-- Set a global variable
GV[ns].varname = "stuff"
GV[ns]["varname"] = "stuff"
-- Read a global variable
print(GV[ns].varname)
-- Clear a global variable (not sure if this one actually works)
GV[ns].varname = nil
immediate=yes
. There's no Lua equivalent to immediate=no
at the moment.- ZombieKnight
- Posts: 337
- Joined: June 27th, 2022, 2:26 pm
- Location: Czech Republic
Re: Global_variables with Lua
Thanks!
- ZombieKnight
- Posts: 337
- Joined: June 27th, 2022, 2:26 pm
- Location: Czech Republic
Re: Global_variables with Lua
...
If I understand right this should create a variable varname and set it to "stuff"
...
But it does nothing
If I understand right this should create a variable varname and set it to "stuff"
Code: Select all
[lua]
code=<<
local GV = wesnoth.experimental.wml.global_vars
local ns = "Bandits_from_Brown_Hills"
GV[ns].varname = "stuff"
GV[ns]["varname"] = "stuff"
>>
[/lua]
But it does nothing
- ZombieKnight
- Posts: 337
- Joined: June 27th, 2022, 2:26 pm
- Location: Czech Republic
Re: Global_variables with Lua
Using wesnoth.wml_actions ...