[set_variables] doesn't seem to do anything
Moderator: Forum Moderators
[set_variables] doesn't seem to do anything
I'm looking for a way to feed raw WML files into Lua so I can extract data from them, but no matter what I do, I can't get [set_variables] to actually store any data. The following code is in a testing state to show exactly what doesn't work.
Here's my WML:
And here's my Lua:
The first for loop above indicates that the variable consists only of {__varname = 'unit_type_data'}. I can't use wesnoth.get_unit_type_ids, because it needs to work on MP. I'm completely at a loss here...
EDIT: I'm using 1.8.5.
Here's my WML:
Code: Select all
[event]
name=prestart
[set_variables]
name=unit_type_data
[value]
[unit_type]
id=Blood Bat
[/unit_type]
#{core/units/bats/Bat_Blood.cfg}
[/value]
[/set_variables]
[tcg_init]
size={SIZE}
variable=unit_type_data
[/tcg_init]
[/event]
Code: Select all
function W.tcg_init(cfg)
local v = cfg.variable
V.unitTypeList = ''
for k, v in pairs(V[v]) do
wesnoth.message(tostring(k))
wesnoth.message(tostring(v))
end
for unitType in H.child_range(V[v], 'unit_type') do
V.unitTypeList = ('%s%s,'):format(V.unitTypeList, unitType.id)
end
wesnoth.message(V.unitTypeList) --Empty
--V[v] = nil
V.recruitListSize = tonumber(cfg.size) or Map:biggestCastle()
V.recruits = {}
local i = 1
while wesnoth.get_side(i) do
V.recruits[i] = {}
i = i + 1
end
end
EDIT: I'm using 1.8.5.
-
- Inactive Developer
- Posts: 2461
- Joined: August 15th, 2008, 8:46 pm
- Location: Germany
Re: [set_variables] doesn't seem to do anything
You seem to be using the helper.set_metatables stuff which always confuses me so I don't quite understand - however, my guess is you are mistaken about what the variable is supposed to look like.
Here's the "syntactically correct" output from dbms (in wlp) for your unit_type_data variable (dbms(wesnoth.get_variable("unit_type_data"))):
Good idea is also :inspect for doing this, but it however doesn't show the wml table structure.
Here's the "syntactically correct" output from dbms (in wlp) for your unit_type_data variable (dbms(wesnoth.get_variable("unit_type_data"))):
Code: Select all
{
[1] = {
[1] = "unit_type",
[2] = {
id = "Blood Bat"
}
}
}
projects (BfW 1.12):
A Simple Campaign: campaign draft for wml starters • Plan Your Advancements: mp mod
The Earth's Gut: sp campaign • Settlers of Wesnoth: mp scenario • Wesnoth Lua Pack: lua tags and utils
updated to 1.8 and handed over: A Gryphon's Tale: sp campaign
A Simple Campaign: campaign draft for wml starters • Plan Your Advancements: mp mod
The Earth's Gut: sp campaign • Settlers of Wesnoth: mp scenario • Wesnoth Lua Pack: lua tags and utils
updated to 1.8 and handed over: A Gryphon's Tale: sp campaign
Re: [set_variables] doesn't seem to do anything
Supposedly, 'V[v]' should return the same thing as 'wesnoth.get_variable(v)', but that doesn't seem to be the case for tables (see below). BTW, I couldn't find dbms in wlp. Is it only in the 1.9 version?Anonymissimus wrote:You seem to be using the helper.set_metatables stuff which always confuses me so I don't quite understand
Thanks, I didn't know about that command. It was very useful here.Good idea is also :inspect for doing this, but it however doesn't show the wml table structure.
I think I know enough to get it working now. Here's my current code with all the debugging statements:
WML:
Code: Select all
[event]
name=prestart
[set_variables]
name=unit_type_data
[value]
{core/units/bats}
[/value]
[/set_variables]
[tcg_init]
size={SIZE}
variable=unit_type_data
[/tcg_init]
[/event]
Code: Select all
function W.tcg_init(cfg)
local v = cfg.variable
V.unitTypeList = ''
local data = wesnoth.get_variable(v)
--Shows indexes 1,2,3, but no __varname
for k, v in pairs(data) do
wesnoth.message(tostring(k))
wesnoth.message(tostring(v))
end
--Shows only the __varname index
for k, v in pairs(V[v]) do
wesnoth.message(tostring(k))
wesnoth.message(tostring(v))
end
--Doesn't do anything
for unitType in H.child_range(V[v], 'unit_type') do
V.unitTypeList = ('%s%s,'):format(V.unitTypeList, unitType.id)
end
wesnoth.message(V.unitTypeList) --Empty
--Commented out for game save inspection
--V[v] = nil
V.recruitListSize = tonumber(cfg.size) or Map:biggestCastle()
V.recruits = {}
local i = 1
while wesnoth.get_side(i) do
V.recruits[i] = {}
i = i + 1
end
end
I don't have time to work on it right now, but thanks for your help. I'll let you know later if it still doesn't help.
- Elvish_Hunter
- Posts: 1575
- Joined: September 4th, 2009, 2:39 pm
- Location: Lintanir Forest...
Re: [set_variables] doesn't seem to do anything
It is only in the version available on Wesnoth-UMC-Dev, trunk branch, for now.Luther wrote:BTW, I couldn't find dbms in wlp. Is it only in the 1.9 version?
Current maintainer of these add-ons, all on 1.16:
The Sojournings of Grog, Children of Dragons, A Rough Life, Wesnoth Lua Pack, The White Troll (co-author)
The Sojournings of Grog, Children of Dragons, A Rough Life, Wesnoth Lua Pack, The White Troll (co-author)
-
- Inactive Developer
- Posts: 2461
- Joined: August 15th, 2008, 8:46 pm
- Location: Germany
Re: [set_variables] doesn't seem to do anything
My dbms function is here:
https://wesnoth-umc-dev.svn.sourceforge ... _utils.lua
I wrote it since I was always confused about tables, specifically about why certain tables aren't also wml tables.
Interesting thing is that your {core/units/bats/Bat_Blood.cfg} inclusion works here...loading arbitrary wml syntax-like data into lua tables...
https://wesnoth-umc-dev.svn.sourceforge ... _utils.lua
I wrote it since I was always confused about tables, specifically about why certain tables aren't also wml tables.
Interesting thing is that your {core/units/bats/Bat_Blood.cfg} inclusion works here...loading arbitrary wml syntax-like data into lua tables...
projects (BfW 1.12):
A Simple Campaign: campaign draft for wml starters • Plan Your Advancements: mp mod
The Earth's Gut: sp campaign • Settlers of Wesnoth: mp scenario • Wesnoth Lua Pack: lua tags and utils
updated to 1.8 and handed over: A Gryphon's Tale: sp campaign
A Simple Campaign: campaign draft for wml starters • Plan Your Advancements: mp mod
The Earth's Gut: sp campaign • Settlers of Wesnoth: mp scenario • Wesnoth Lua Pack: lua tags and utils
updated to 1.8 and handed over: A Gryphon's Tale: sp campaign