loading WML from a file into a table
Moderator: Forum Moderators
-
- Developer
- Posts: 546
- Joined: January 12th, 2011, 2:18 am
- Location: Pennsylvania, USA
loading WML from a file into a table
for my campaign I decided it would be useful if I could read the faction files in {multiplayer/factions} and put the contents of a [multiplayer_side] tag into a lua table, and then send the contents of some of the keys into wesnoth variables.
currently, I tried the following inside a WML [event]:
and then some WML code to put the contents of "faction_name" on the screen (should put "Undead" on the screen if it works (the contents of the 'id' key in the file read)
it gave the following error:
[string "..."]:3: attempt to index local 'faction_table', nil value
and then some tracebacks.
I'm getting the sense that the contents of undead-aoh.cfg were put into scalar instead of a table, but I'm not sure how to set it up for it to go into a table.
How would I do that?
currently, I tried the following inside a WML [event]:
Code: Select all
[set_variable]
name=Default_Era_Undead
[value]
{multiplayer/factions/undead-aoh.cfg}
[/value]
[set_variable]
[lua]
code=<<
faction_table = wesnoth.get_variable("Default_Era_Undead")
wesnoth.set_variable("faction_name", faction_table.id)
>>
[/lua]
it gave the following error:
[string "..."]:3: attempt to index local 'faction_table', nil value
and then some tracebacks.
I'm getting the sense that the contents of undead-aoh.cfg were put into scalar instead of a table, but I'm not sure how to set it up for it to go into a table.
How would I do that?
Co-Author of Winds of Fate
My Add-ons: Random Campaign, Custom Campaign, Ultimate Random Maps, Era of Legends, Gui Debug Tools
Erfworld: The comic that lead me to find Wesnoth.
My Add-ons: Random Campaign, Custom Campaign, Ultimate Random Maps, Era of Legends, Gui Debug Tools
Erfworld: The comic that lead me to find Wesnoth.
Re: loading WML from a file into a table
I think you meant to write set_variables, not set_variable.
http://www.wesnoth.org/wiki/User:Sapient... "Looks like your skills saved us again. Uh, well at least, they saved Soarin's apple pie."
-
- Developer
- Posts: 546
- Joined: January 12th, 2011, 2:18 am
- Location: Pennsylvania, USA
Re: loading WML from a file into a table
changing [set_variable] to [set_variables] got rid of the error code, but "faction_name" still isn't being loaded with the desired data.
is the fact that I'm running this code under a SP Campaign have anything to do with anything?
is the fact that I'm running this code under a SP Campaign have anything to do with anything?
Co-Author of Winds of Fate
My Add-ons: Random Campaign, Custom Campaign, Ultimate Random Maps, Era of Legends, Gui Debug Tools
Erfworld: The comic that lead me to find Wesnoth.
My Add-ons: Random Campaign, Custom Campaign, Ultimate Random Maps, Era of Legends, Gui Debug Tools
Erfworld: The comic that lead me to find Wesnoth.
Re: loading WML from a file into a table
You're forgetting that all the keys are inside a [multiplayer_side] tag. Presumably changing wesnoth.set_variable("faction_name", faction_table.id) to wesnoth.set_variable("faction_name", faction_table.multiplayer_side.id) would work.
However, you don't need Lua for that:
However, you don't need Lua for that:
Code: Select all
[set_variables]
name=Default_Era_Undead
[value]
{multiplayer/factions/undead-aoh.cfg}
[/value]
[set_variables]
{VARIABLE faction_name $Default_Era_Undead.multiplayer_side.id}
-
- Developer
- Posts: 546
- Joined: January 12th, 2011, 2:18 am
- Location: Pennsylvania, USA
Re: loading WML from a file into a table
misreading the wiki caused me to think lua was necessary.
looks like what I want to do might be possible using only WML, this question should settle it:
I want:
Default_Era_Undead.multiplayer_side.image=units/undead-necromancers/lich.png
(or in some other variable)
so I can do:
message="&$Default_Era.multiplayer_side.image~RC(magenta>red)"
but i am running into problems because:
Default_Era_Undead.multiplayer_side.image="units/undead-necromancers/lich.png"
and it looks like there is no way to strip the " (double quotes) from the variable value. Do I need lua to strip the " ?
looks like what I want to do might be possible using only WML, this question should settle it:
I want:
Default_Era_Undead.multiplayer_side.image=units/undead-necromancers/lich.png
(or in some other variable)
so I can do:
message="&$Default_Era.multiplayer_side.image~RC(magenta>red)"
but i am running into problems because:
Default_Era_Undead.multiplayer_side.image="units/undead-necromancers/lich.png"
and it looks like there is no way to strip the " (double quotes) from the variable value. Do I need lua to strip the " ?
Co-Author of Winds of Fate
My Add-ons: Random Campaign, Custom Campaign, Ultimate Random Maps, Era of Legends, Gui Debug Tools
Erfworld: The comic that lead me to find Wesnoth.
My Add-ons: Random Campaign, Custom Campaign, Ultimate Random Maps, Era of Legends, Gui Debug Tools
Erfworld: The comic that lead me to find Wesnoth.
Re: loading WML from a file into a table
As far as I know, there's no way to store an image in a variable. What are you trying to do, exactly?
Re: loading WML from a file into a table
If you meant image="$Default_Era_Undead.multiplayer_side.image~RC(magenta>red)", then yes.SigurdTheDragon wrote: misreading the wiki caused me to think lua was necessary.
looks like what I want to do might be possible using only WML, this question should settle it:
I want:
Default_Era_Undead.multiplayer_side.image=units/undead-necromancers/lich.png
(or in some other variable)
so I can do:
message="&$Default_Era.multiplayer_side.image~RC(magenta>red)"
Quotes simply enclose values, they're not part of them. You don't ever need to strip quotes.SigurdTheDragon wrote:but i am running into problems because:
Default_Era_Undead.multiplayer_side.image="units/undead-necromancers/lich.png"
and it looks like there is no way to strip the " (double quotes) from the variable value. Do I need lua to strip the " ?
-
- Developer
- Posts: 546
- Joined: January 12th, 2011, 2:18 am
- Location: Pennsylvania, USA
Re: loading WML from a file into a table
Ok, here's what was going wrong with my testing.
the first message key throws up a conains invalid wml error, the second one works as intended to display a pic. the "=" is necessary for the second to display properly.
I was just using the above minus the option tag to test the code form.
I had assumed that the message key in each place was identical in behavor. also for a while I didn't realize the = was needed
since how it works in the [option] tag is what I was looking to do, that solves my question.
I guess I didn't need lua after all. Thanks, everyone
Code: Select all
[set_variable]
name=faction_pic
value=$Default_Era_Undead.multiplayer_side.image
[/set_variable]
[message]
speaker=narrator
message="&$faction_pic~RC(magenta>red)=undead="
[option]
message="&$faction_pic~RC(magenta>red)=undead="
[/option]
[/message]
I was just using the above minus the option tag to test the code form.
I had assumed that the message key in each place was identical in behavor. also for a while I didn't realize the = was needed
since how it works in the [option] tag is what I was looking to do, that solves my question.
I guess I didn't need lua after all. Thanks, everyone
Co-Author of Winds of Fate
My Add-ons: Random Campaign, Custom Campaign, Ultimate Random Maps, Era of Legends, Gui Debug Tools
Erfworld: The comic that lead me to find Wesnoth.
My Add-ons: Random Campaign, Custom Campaign, Ultimate Random Maps, Era of Legends, Gui Debug Tools
Erfworld: The comic that lead me to find Wesnoth.