counting unit_type
Moderator: Forum Moderators
Forum rules
- Please use [code] BBCode tags in your posts for embedding WML snippets.
- To keep your code readable so that others can easily help you, make sure to indent it following our conventions.
-
- Posts: 11
- Joined: February 20th, 2023, 8:38 am
counting unit_type
Hello. I have a problem with the following code.
It sometimes generate the following error
the purpose of the code is to count how many units of type Siege_2 a side have so if there is another way, tell me about
Code: Select all
[if]
[have_unit]
type=Siege_2
[/have_unit]
[then]
[store_unit]
[filter]
type=Siege_2
[/filter]
variable=Count_Siege_2
kill=no
[/store_unit]
[foreach]
array=Count_Siege_2
[do]
{VARIABLE_OP counting add 1} # counting is assigned to 0 in the prestart
[/do]
[/foreach]
[/then]
[/if]
Code: Select all
20230410 19:16:47 error scripting/lua: lua/core/wml.lua:232: bad argument #2 to 'set_variable_local' (WML table or scalar expected, got table)
stack traceback:
[C]: in function 'wml.set_variable'
lua/core/wml.lua:232: in metamethod 'newindex'
lua/wml-utils.lua:47: in field 'write'
lua/wml-tags.lua:406: in local 'cmd'
lua/wml-utils.lua:144: in field 'handle_event_commands'
lua/wml-flow.lua:19: in local 'cmd'
lua/wml-utils.lua:144: in field 'handle_event_commands'
lua/wml-flow.lua:5: in function <lua/wml-flow.lua:4>
Re: counting unit_type
Try this instead of the [foreach] and without needing to define counting first:
Code: Select all
[set_variable]
name=counting
value=$Count_Siege_2.length
[/set_variable]
Last edited by Toranks on April 11th, 2023, 3:52 am, edited 1 time in total.
- Celtic_Minstrel
- Developer
- Posts: 2235
- Joined: August 3rd, 2012, 11:26 pm
- Location: Canada
- Contact:
Re: counting unit_type
Other than the typo, Toranks's code will do what you want.
That aside, this seems like a potential bug in
That aside, this seems like a potential bug in
[set_variable]
…