PDA

View Full Version : Help with a simple template



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>

TarynWinterblade
June 2nd, 2007, 07:19
Does that make sense?
Is it possible to define this xml in such a way that the number of states is not limited?


It took me a bit to figure this out too...

The key is merge rules, described in templates: https://www.fantasygrounds.com/modguide/templates.xcp

Basically, what you'd want to do is setup your template to look like:


<template name="multistate_template">
<genericcontrol>
<state_icon mergerule="add" />
<script file="Scripts/multistate_template.lua" />
</genericcontrol>
</template>


This makes it so that each instance of state_icon gets added to the table.

Toadwart
June 3rd, 2007, 01:10
Thanks for that Taryn. :D
Had a bit of a brain freeze and had skipped over the merge rules stuff thinking it was unrelated to my problem. :o

TarynWinterblade
June 3rd, 2007, 02:37
Thanks for that Taryn. :D
Had a bit of a brain freeze and had skipped over the merge rules stuff thinking it was unrelated to my problem. :o

I've done that too many times before on things myself :o

DNH
June 16th, 2007, 14:57
perhaps an easier way of implementing the old multistate is to take the cue from the melee/missile indicator toggle in charsheet_combat.xml. essentially, this toggles the field between two values and displays a value accordingly. it IS extensible and you are not restricted to a number value either. i use it successfully to cycle through the various weapon types (S, B, P etc) and will probably use it elsewhere where choices are restricted from among a closed set.