Trouble with helper.set_variable_array example on wiki
Moderator: Forum Moderators
- Pentarctagon
- Project Manager
- Posts: 5599
- Joined: March 22nd, 2009, 10:50 pm
- Location: Earth (occasionally)
Trouble with helper.set_variable_array example on wiki
The wiki has a simple example of how to use helper.set_variable_array(). However, the following code based on that example doesn't work:
The message displayed is blank, and the following errors are logged:
What's going on here?
Code: Select all
[event]
name="turn 1"
[lua]
code=<<
local t1 = 1
local t2 = 2
local t3 = 3
helper.set_variable_array("target", { t1, t2, t3 })
>>
[/lua]
[message]
message="$target[1]"
[/message]
[/event]
Code: Select all
20170429 17:27:12 warning scripting/lua: Cannot resolve variablename 'target[0]' for writing. when attempting to write a 'number'
20170429 17:27:12 warning scripting/lua: Cannot resolve variablename 'target[1]' for writing. when attempting to write a 'number'
20170429 17:27:12 warning scripting/lua: Cannot resolve variablename 'target[2]' for writing. when attempting to write a 'number'
99 little bugs in the code, 99 little bugs
take one down, patch it around
-2,147,483,648 little bugs in the code
take one down, patch it around
-2,147,483,648 little bugs in the code
Re: Trouble with helper.set_variable_array example on wiki
uhm well how would you expect how the variables wml look after it ?
Scenario with Robots SP scenario (1.11/1.12), allows you to build your units with components, PYR No preperation turn 1.12 mp-mod that allows you to select your units immideately after the game begins.
- Pentarctagon
- Project Manager
- Posts: 5599
- Joined: March 22nd, 2009, 10:50 pm
- Location: Earth (occasionally)
Re: Trouble with helper.set_variable_array example on wiki
I would expect it to look like the example on the wiki says it should look.
99 little bugs in the code, 99 little bugs
take one down, patch it around
-2,147,483,648 little bugs in the code
take one down, patch it around
-2,147,483,648 little bugs in the code
Re: Trouble with helper.set_variable_array example on wiki
no, i meant please post the concrete wml code, for example of an equivalent [set_variables][literal]
Scenario with Robots SP scenario (1.11/1.12), allows you to build your units with components, PYR No preperation turn 1.12 mp-mod that allows you to select your units immideately after the game begins.
- Pentarctagon
- Project Manager
- Posts: 5599
- Joined: March 22nd, 2009, 10:50 pm
- Location: Earth (occasionally)
Re: Trouble with helper.set_variable_array example on wiki
Well, it would probably be something like:
which I'm pretty sure isn't valid, but IIRC Wesnoth still allows doing something like this(though it warns about it in the log):
Either way though, the following still doesn't work, even though it doesn't cause any errors to appear in the log:
In this case I would expect the WML array to look like this:
but instead the message is still blank, and there's also no "target" WML variable at all when looking at it through :inspect.
Code: Select all
[set_variables]
name=target
[value]
1
[/value]
[value]
2
[/value]
[value]
3
[/value]
[/set_variables]
Code: Select all
{VARIABLE target[0] 1}
Code: Select all
[event]
name="turn 1"
[lua]
code=<<
local t1 = 1
local t2 = 2
local t3 = 3
helper.set_variable_array("target", { t=t1, t=t2, t=t3 })
>>
[/lua]
[message]
message="$target[1].t"
[/message]
[/event]
Code: Select all
[set_variables]
name=target
[value]
t=1
[/value]
[value]
t=2
[/value]
[value]
t=3
[/value]
[/set_variables]
99 little bugs in the code, 99 little bugs
take one down, patch it around
-2,147,483,648 little bugs in the code
take one down, patch it around
-2,147,483,648 little bugs in the code
Re: Trouble with helper.set_variable_array example on wiki
quite possible that support for this was removed in wesnoth 1.13 . But even if it wasn't evenrythign that generated wanrings is bad code and hsoul be fixed.Pentarctagon wrote: but IIRC Wesnoth still allows doing something like this(though it warns about it in the log):Code: Select all
{VARIABLE target[0] 1}
yes this codePentarctagon wrote:
Either way though, the following still doesn't work, even though it doesn't cause any errors to appear in the log:
but instead the message is still blank, and there's also no "target" WML variable at all when looking at it through :inspect.
{ t=t1, t=t2, t=t3 }
is basically equivalent to { t=t3 }
since you are just overwriting the same 't' value of that lua table 3 times.helper.set_variable_array
expects an array (that is: a table with ascenting integer keys) of wml tables, so the correct code is helper.set_variable_array("target", { {t=t1}, {t=t2}, {t=t3} })
, where { {t=t1}, {t=t2}, {t=t3} }
is an array and {t=t3}
etc. are wml tables each.Also note that
{ t=t1, t=t2, t=t3 }
has no integer keyssa at all (the only key is t) so the array is empty from helper.set_variable_arrays point of viewScenario with Robots SP scenario (1.11/1.12), allows you to build your units with components, PYR No preperation turn 1.12 mp-mod that allows you to select your units immideately after the game begins.
- Pentarctagon
- Project Manager
- Posts: 5599
- Joined: March 22nd, 2009, 10:50 pm
- Location: Earth (occasionally)
Re: Trouble with helper.set_variable_array example on wiki
Ah, alright then, thanks.
99 little bugs in the code, 99 little bugs
take one down, patch it around
-2,147,483,648 little bugs in the code
take one down, patch it around
-2,147,483,648 little bugs in the code