Toadwart
June 2nd, 2007, 00:11
Hi all, hoping someone can help before my last remaining braincell melts.
Have been trying to set up a very simple template to mimic the behaviour of the old "multistate" field in FG1. However, I can't get my head around how to access my custom tags from within the script.
This is the template definition
<template name="multistate_template">
<genericcontrol>
<script file="Scripts/multistate_template.lua" />
</genericcontrol>
</template>
and the script file (multistate_template.lua)
function onInit()
-- just some debuggging statements at present
-- but will eventually use the setIcon function
print(state_icon[1]);
for k,v in ipairs(state_icon) do
print(k);
end
end
And finally the template is used inside a windowclass:
<multistate_template name = "SomeMultistateField" >
<bounds>89, 230, 108, 21</bounds>
<state_icon>icon1</state_icon>
<state_icon>icon2</state_icon>
<state_icon>icon3</state_icon>
<state_icon>icon4</state_icon>
</multistate_template>
When I run it the console gets this output:
Script Notice: icon4
Script Notice: 1
I think I understand why it only finds a single node (the table created from the xml is named "state_icon" and that name must be unique). However, I can't see how to define the xml to allow for an arbitrary number of states.
i.e. the table created from the xml looks like this:
state_icon = {[1] = "icon4" }
while I was expecting this:
state_icon = {[1] = "icon1",
[2] = "icon2" ,
[3] = "icon3" ,
[4] = "icon4"
}
Does that make sense?
Is it possible to define this xml in such a way that the number of states is not limited?
The following approach is a workaround but the names would have to be hardcoded into the script as state_icon1, state_icon2, etc
<state_icon1>icon1</state_icon1>
<state_icon2>icon2</state_icon2>
<state_icon3>icon3</state_icon3>
<state_icon4>icon4</state_icon4>
Have been trying to set up a very simple template to mimic the behaviour of the old "multistate" field in FG1. However, I can't get my head around how to access my custom tags from within the script.
This is the template definition
<template name="multistate_template">
<genericcontrol>
<script file="Scripts/multistate_template.lua" />
</genericcontrol>
</template>
and the script file (multistate_template.lua)
function onInit()
-- just some debuggging statements at present
-- but will eventually use the setIcon function
print(state_icon[1]);
for k,v in ipairs(state_icon) do
print(k);
end
end
And finally the template is used inside a windowclass:
<multistate_template name = "SomeMultistateField" >
<bounds>89, 230, 108, 21</bounds>
<state_icon>icon1</state_icon>
<state_icon>icon2</state_icon>
<state_icon>icon3</state_icon>
<state_icon>icon4</state_icon>
</multistate_template>
When I run it the console gets this output:
Script Notice: icon4
Script Notice: 1
I think I understand why it only finds a single node (the table created from the xml is named "state_icon" and that name must be unique). However, I can't see how to define the xml to allow for an arbitrary number of states.
i.e. the table created from the xml looks like this:
state_icon = {[1] = "icon4" }
while I was expecting this:
state_icon = {[1] = "icon1",
[2] = "icon2" ,
[3] = "icon3" ,
[4] = "icon4"
}
Does that make sense?
Is it possible to define this xml in such a way that the number of states is not limited?
The following approach is a workaround but the names would have to be hardcoded into the script as state_icon1, state_icon2, etc
<state_icon1>icon1</state_icon1>
<state_icon2>icon2</state_icon2>
<state_icon3>icon3</state_icon3>
<state_icon4>icon4</state_icon4>