avatar counting units in certain category
May 19, 2010 10:44PM
How can you count up how much units of a category you got?

Let's say I need to know how many units of category "individual" i have.
In the validator I put something like:

for i,unit in twArmy:units() do

if (unit.categories.category=='Individual') then
....


It doesn't seem to be recognized, I assumed this matched the Units.xml structure, but I guess I was wrong...

can anyone help ?



Edited 1 time(s). Last edit at 05/20/2010 07:57AM by francio.
avatar Re: Edit displays/Validation
May 20, 2010 06:27AM
Category is not exposed inside the objects passed into the LUA interpreter.
For the validator on my list, I added an extra field with the same contents as the category and used that to verify it.



Edited 1 time(s). Last edit at 05/20/2010 06:35AM by JohnOC.
avatar Re: Edit displays/Validation
May 20, 2010 06:43AM
To see what fields are available and how they are addressed, you can pass a complex object to the twNotice() output function. Like this

twNotice(twArmy)

for i,unit in twArmy:units() do
twNotice(unit)
for j, bonus in unit:bonuses() do
twNotice(bonus)
end
end

That will give you the structure of all the objects you have to play with.
avatar Re: counting units in certain category
May 20, 2010 08:08AM
JohnOC have hit the nail on the head.
Sorry for holes in the documentation on this matter.
Maybe I should add categories to Lua interface?


BTW: You ruleset does not work in online editor because of the default display XML.
You should use 'default' field instead of 'value' here.
You have something like this:
<displayFields>
    <field>
      <name>something</name>
      <value>1</value>
    </field>
</displayFields>
it should look like this:
<displayFields>
    <field>
      <name>something</name>
      <default>1</default>
    </field>
</displayFields>



avatar Re: counting units in certain category
May 21, 2010 10:03PM
francio Wrote:
-------------------------------------------------------
> JohnOC have hit the nail on the head.
> Sorry for holes in the documentation on this
> matter.
> Maybe I should add categories to Lua interface?


I would find that very useful for my code. Anyone writing a Warhammer 40k ruleset needs to be able to validate numbers of allowed choices by category, and it makes sense not to have to duplicate that info in the unit.xml.
Sorry, only registered users may post in this forum.

Click here to login

© 2009,2010 FSW; almost valid XHTML; generated in: 0.03s;