[solved] How to move WML table
Moderator: Forum Moderators
- ZombieKnight
- Posts: 250
- Joined: June 27th, 2022, 2:26 pm
- Location: Czech Republic
[solved] How to move WML table
Hi
I've got this saved in
How to move all of its content into wml.variables?
Any ideas?
I've got this saved in
Code: Select all
wml.variables["save_data"]
Any ideas?
Last edited by ZombieKnight on May 7th, 2024, 10: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
-
- Posts: 1282
- Joined: August 26th, 2018, 11:46 pm
- Location: A country place, far outside the Wire
- ZombieKnight
- Posts: 250
- Joined: June 27th, 2022, 2:26 pm
- Location: Czech Republic
Re: How to move WML table
Sorry?
I've found the wiki page (https://wiki.wesnoth.org/LuaAPI/wml#wml ... access.get) and I have no idea how to use it for moving wml table right into wml.variables.
Could you explain it a bit more?
It's a function that just returns a value or does it do even something else?
What is this supposed to do:
I've found the wiki page (https://wiki.wesnoth.org/LuaAPI/wml#wml ... access.get) and I have no idea how to use it for moving wml table right into wml.variables.
Could you explain it a bit more?
It's a function that just returns a value or does it do even something else?
What is this supposed to do:
Code: Select all
function get_recall_list(side)
wesnoth.fire("store_unit", { x = "recall", variable = "LUA_recall_list" })
local l = wml.array_access.get "LUA_recall_list"
wml.variables.LUA_recall_list = nil
return l
end
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
Re: How to move WML table
wml.variables is not real table, so you cant insert another table into it. For regular tables it is just table.insert(destination_table, wml_table).
- ZombieKnight
- Posts: 250
- Joined: June 27th, 2022, 2:26 pm
- Location: Czech Republic
Re: How to move WML table
Okay,
So I've got a table of tables... how to put these tables into wml.variables then?
What are you thinking about?
...
Or the first table is on the right place... so can't I just remove those [save_data] tags from it and leave it there?
So I've got a table of tables... how to put these tables into wml.variables then?
What are you thinking about?
...
Or the first table is on the right place... so can't I just remove those [save_data] tags from it and leave it there?
Last edited by ZombieKnight on May 6th, 2024, 6:59 pm, 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
Re: How to move WML table
You cant put them to wml.variables. You can think of wml.variables as function, not as table. It reflects state of wml variables, but itself is not wml variables.
- ZombieKnight
- Posts: 250
- Joined: June 27th, 2022, 2:26 pm
- Location: Czech Republic
Re: How to move WML table
Oh...
So where to put them so I can acces them later using
wml.variables[my_var]?
So where to put them so I can acces them later using
wml.variables[my_var]?
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
Re: How to move WML table
Assign them with the API you have available to create wml variables. Including wml.variables if you prefer. Those like set_variable, set_variables, wml.array_access.set, wml.array_variables, wml.variables_proxy.
- Celtic_Minstrel
- Developer
- Posts: 2273
- Joined: August 3rd, 2012, 11:26 pm
- Location: Canada
- Contact:
Re: How to move WML table
Loading it back in is going to be pretty much the same procedure as saving it was. The scalar ones should be easy, literally the exact same loop you used to save but flip the assignment. Container variables will be a bit more tricky. I think something along these lines may work?
There might be a more efficient way (as each assignment here is probably looping over all of
Code: Select all
local tags = {}
for index, elem in ipairs(save_data) do
tags[elem.tag] = true
end
for tag,_ in pairs(tags) do
wml.array_variables[tag] = wml.child_array(save_data, tag)
end
save_data
again), but I think that approach should do the job.- ZombieKnight
- Posts: 250
- Joined: June 27th, 2022, 2:26 pm
- Location: Czech Republic
Re: How to move WML table
Ok, I'll try it but... have you seen the code t
for erasing all the container variables?
for erasing all the container variables?
Code: Select all
for index, elem in ipairs(wml.all_variables) do
wml.variables[""..elem[1].."[0]"] = nil end
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: 250
- Joined: June 27th, 2022, 2:26 pm
- Location: Czech Republic
Re: How to move WML table
Not sure... you meantCeltic_Minstrel wrote: ↑May 6th, 2024, 11:07 pm There might be a more efficient way (as each assignment here is probably looping over all ofsave_data
again), but I think that approach should do the job.
wml.variables.save_data
?I extract the data from global using this:
Code: Select all
wesnoth.wml_actions.get_global_variable(
{
namespace="Bandits_from_Brown_Hills",
to_local="save_data",
from_global="save_file",
side=1,
}
)
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: 250
- Joined: June 27th, 2022, 2:26 pm
- Location: Czech Republic
Re: How to move WML table
...And I really think your code is really wrong...
returns
Code: Select all
for index, elem in ipairs(wml.variables["save_data"]) do
std_print(index, elem)
end
Code: Select all
1 table: 0x5596a93b5720
2 table: 0x5596b4cc6200
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: 250
- Joined: June 27th, 2022, 2:26 pm
- Location: Czech Republic
Re: How to move WML table
I have no idea how I made this ...
Ladies and gentlemen, I present you wml.variables replacer:
Only units, menu items, events, and sides to go!
Thanks for help so far (and I'd be glad if you'd keep helping me ^^)
Ladies and gentlemen, I present you wml.variables replacer:
Code: Select all
wesnoth.wml_actions.get_global_variable(
{
namespace="Bandits_from_Brown_Hills",
to_local="save_data",
from_global="save_file",
side=1,
}
)
for key, value in pairs(wml.variables["save_data"]) do
if type(value) ~= "table" then
wml.variables[key] = value
end
end
for index, elem in ipairs(wml.variables["save_data"]) do
if elem[1] ~= "save_data" then
local i = 0
while wml.variables[""..elem[1].."["..i.."]"] ~= nil do
i = i + 1
end
wml.variables[""..elem[1].."["..i.."]"] = elem[2]
end
end
wml.variables["save_data"] = nil
Only units, menu items, events, and sides to go!
Thanks for help so far (and I'd be glad if you'd keep helping me ^^)
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