[~solved] Global_variables with Lua
Moderator: Forum Moderators
- ZombieKnight
- Posts: 282
- 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.
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: 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: 282
- Joined: June 27th, 2022, 2:26 pm
- Location: Czech Republic
Re: Global_variables with Lua
Thanks!
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
- ZombieKnight
- Posts: 282
- 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
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
- ZombieKnight
- Posts: 282
- Joined: June 27th, 2022, 2:26 pm
- Location: Czech Republic
Re: Global_variables with Lua
Using wesnoth.wml_actions ...
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