Filtering unit list of modifications

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
hermestrismi
Posts: 626
Joined: February 6th, 2016, 11:28 pm
Location: Tunisia
Contact:

Filtering unit list of modifications

Post by hermestrismi »

Let's say that I have a unit with a list of custom variables inside modifications.
Now, I need to filter the list of modifications to check if it had a match.
The result will turn false if it had this variables value and true if it hadn't.
If I use [foreach] tag, the process will be repeated.
For example:

Code: Select all

[indent][modifications]
[object]
have_sword=magic
[/object]
[object]
have_sword_iron=yes
[/object]
[/modifications][/indent]
Now, if I used

Code: Select all

[indent]
[foreach]
array=unit.modifications.object
[do]
[if]
[variable]
name=unit.modifications.object[$i]
equals=have_sword_iron
[/variable]
[message]
....briefly say HELLO for example...
[/message]
[else]
....briefly say Noway for example...
[/else]
[/if]
[/do]
[/foreach][/indent]
The result will be : true then false.
Briefly, how to check the whole array before return the final result
User avatar
Ravana
Forum Moderator
Posts: 3018
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: Filtering unit list of modifications

Post by Ravana »

name=unit.modifications.object[$i] should be name=unit.modifications.object[$i].have_sword
User avatar
hermestrismi
Posts: 626
Joined: February 6th, 2016, 11:28 pm
Location: Tunisia
Contact:

Re: Filtering unit list of modifications

Post by hermestrismi »

Ravana wrote: December 8th, 2023, 10:19 pm name=unit.modifications.object[$i] should be name=unit.modifications.object[$i].have_sword
:annoyed: ^_^ how did I mess that ? 😳 😳 it was in front of me for one hour... thank you
Post Reply