Count units on a side?

The place to post your WML questions and answers.

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.
Post Reply
User avatar
LordAwsomeness
Posts: 203
Joined: August 12th, 2013, 2:20 pm
Location: U.S.A.

Count units on a side?

Post by LordAwsomeness »

is there a way to count the units on a side? specifically units that have a static effect such as poisoned or slowed?
- Been playing Wesnoth since 2004 and the 1.0.x versions.
- Creator of Undead Invasion MP Scenario Pack.
- Creator of Valeria MP Adventure
- Creator of LA_RPG ERA
User avatar
josteph
Inactive Developer
Posts: 741
Joined: August 19th, 2017, 6:58 pm

Re: Count units on a side?

Post by josteph »

Code: Select all

[lua]
    code = << wml.variables.foo = #wesnoth.get_units { side=1, wml.tag.filter_wml { wml.tag.status { poisoned='yes' } } } >>
[/lua]
and then access the WML variable $foo.
User avatar
LordAwsomeness
Posts: 203
Joined: August 12th, 2013, 2:20 pm
Location: U.S.A.

Re: Count units on a side?

Post by LordAwsomeness »

josteph wrote: October 16th, 2019, 3:30 am

Code: Select all

[lua]
    wml.variables.foo = #wesnoth.get_units { side=1, wml.tag.filter_wml { wml.tag.status { poisoned='yes' } } }
[/lua]
and then access the WML variable $foo.
I am unfamiliar with integrating lua into wml. do I need to just copy and paste that lua syntax or do I have to do something more?
- Been playing Wesnoth since 2004 and the 1.0.x versions.
- Creator of Undead Invasion MP Scenario Pack.
- Creator of Valeria MP Adventure
- Creator of LA_RPG ERA
User avatar
josteph
Inactive Developer
Posts: 741
Joined: August 19th, 2017, 6:58 pm

Re: Count units on a side?

Post by josteph »

You can't just paste lua syntax into WML, you have to wrap it in [lua] tags. [lua] tags are ActionWML and can be used wherever ActionWML is allowed, like inside events and menu items and so on.

I edited the previous post to correct a syntax error, make sure to use the new version.

https://wiki.wesnoth.org/LuaWML#The_.5Blua.5D_tag
User avatar
Ravana
Forum Moderator
Posts: 3002
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: Count units on a side?

Post by Ravana »

You can store units in WML as well and check length.

Also, filter_wml is not needed for status anymore since 1.12 I think.
User avatar
LordAwsomeness
Posts: 203
Joined: August 12th, 2013, 2:20 pm
Location: U.S.A.

Re: Count units on a side?

Post by LordAwsomeness »

Ravana wrote: October 16th, 2019, 6:12 am You can store units in WML as well and check length.

Also, filter_wml is not needed for status anymore since 1.12 I think.
oh interesting. what would I use to check the wml instead of filter wml?
- Been playing Wesnoth since 2004 and the 1.0.x versions.
- Creator of Undead Invasion MP Scenario Pack.
- Creator of Valeria MP Adventure
- Creator of LA_RPG ERA
User avatar
Ravana
Forum Moderator
Posts: 3002
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: Count units on a side?

Post by Ravana »

status: (Version 1.13.0 and later only) matches if the unit has the specified status active. This can be a comma-separated list, in which case the unit will match as long as it has one of the listed statuses active
Post Reply