[SOLVED] Side filter does not seem to work

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
Sventimir
Posts: 8
Joined: November 11th, 2020, 9:01 am

[SOLVED] Side filter does not seem to work

Post by Sventimir »

In a multiplayer scenario that I'm working on, I want a mechanics inspired by games like Heroes of Might and Magic. Namely, I want the list of units a leader can recruit depend on the type of castle they're currently in. To do it, I'm using moveto and exit_hex events as follows:

Code: Select all

# recruiting elves
[event]
    name=moveto
    first_time_only=no
    [filter]
        side=$unit.side
        side=1,2,3,4
        canrecruit=yes
        x,y=70,41
    [/filter]
    [set_recruit]
        side=$side_number
        recruit=Elvish Archer,Elvish Fighter,Elvish Scout,Elvish Shaman,Wose,Mage
    [/set_recruit]
[/event]
[event]
    name=exit_hex
    first_time_only=no
    [filter]
        side=$unit.side
        side=1,2,3,4
        canrecruit=yes
        x,y=70,41
    [/filter]
    [set_recruit]
        side=$side_number
        recruit=Peasant,Spearman,Bowman,Mage,Cavalryman,Horseman,Heavy Infantryman,Fencer,Footpad,Thug,Sergeant,Thief,Woodsman,Poacher
    [/set_recruit]
[/event]
This works almost as expected, except the filter does not seem to work. Event seems to be triggered by all sides, not only 1-4. Also the effect seems to apply to all sides, not only to the current side. How can I make it work only for sides 1-4 and to apply only to the side which triggered the event?
Last edited by Sventimir on August 14th, 2023, 7:38 am, edited 1 time in total.
User avatar
Celtic_Minstrel
Developer
Posts: 2241
Joined: August 3rd, 2012, 11:26 pm
Location: Canada
Contact:

Re: Side filter does not seem to work

Post by Celtic_Minstrel »

This probably isn't your problem, but you should remove side=$unit.side as it does nothing. (If that fixes your issue, then I would say that is a bug.)

Beyond that, I'm not sure what to tell you. As far as I can tell, the code you posted should do exactly what you want it to do. Have you verified with :inspect that other sides are also changing their recruit list at the same time?
Author of The Black Cross of Aleron campaign and Default++ era.
Former maintainer of Steelhive.
User avatar
Ravana
Forum Moderator
Posts: 3018
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: Side filter does not seem to work

Post by Ravana »

To explain further, `side=$unit.side` does not do anything, because there is also `side=1,2,3,4` and last value of each key applies.
Sventimir
Posts: 8
Joined: November 11th, 2020, 9:01 am

Re: Side filter does not seem to work

Post by Sventimir »

Initially I didn't write side=$unit.side, I added it later thinking maybe it'd solve the problem, but it didn't/ Thanks for explanation, anyway.
Have you verified with :inspect that
Not yet. But I observed that other sides' recruitment lists change in a way consistent with what I described above.
User avatar
Ravana
Forum Moderator
Posts: 3018
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: Side filter does not seem to work

Post by Ravana »

You need to understand whether issue is when to change, or how to change. That would give information which tag to focus on.
Sventimir
Posts: 8
Joined: November 11th, 2020, 9:01 am

Re: Side filter does not seem to work

Post by Sventimir »

Okay, I debugged the issue and understood it. The problem was actually not in the piece of code that I have shown, buit in another, handling another type of castle, of which there were multiple instances. The reason for error was my misunderstanding of how [or] tag works. I wrote:

Code: Select all

[filter]
  side=1,2,3,4
  canrecruit=yes
  [or]
    x,y=44,52
    x,y=17,67
  [/or]
[/filter]
Inspection showed that the two x,y conditions are not or-ed, but rather the latter overwrites the first. On top of that or makes it a condition alternative to the previous ones (this is very unintuitive!). When changed to this:

Code: Select all

[filter]
    side=1,2,3,4
    canrecruit=yes
    [and]
        x,y=44,52
        [or]
            x,y=17,67
        [/or]
    [/and]
[/filter]
it works as expected. Thanks everyone for hints!
User avatar
Celtic_Minstrel
Developer
Posts: 2241
Joined: August 3rd, 2012, 11:26 pm
Location: Canada
Contact:

Re: [SOLVED] Side filter does not seem to work

Post by Celtic_Minstrel »

I just had the thought that it would technically be more correct to use [set_extra_recruit] instead of [set_recruit] to achieve your stated mechanics. It only makes a difference if a side can have multiple leaders, so maybe it's not relevant to your scenario, but if you wanted to turn this into a modification that works with any scenario, then you should definitely consider it.
Author of The Black Cross of Aleron campaign and Default++ era.
Former maintainer of Steelhive.
Sventimir
Posts: 8
Joined: November 11th, 2020, 9:01 am

Re: [SOLVED] Side filter does not seem to work

Post by Sventimir »

But set_extra_recruits will define additional recruits attached to the leader, right? To achieve what I want I'd need to set the side's standard recruit list to be empty and only use extra recruits. Right?
User avatar
Celtic_Minstrel
Developer
Posts: 2241
Joined: August 3rd, 2012, 11:26 pm
Location: Canada
Contact:

Re: [SOLVED] Side filter does not seem to work

Post by Celtic_Minstrel »

Yes.
Author of The Black Cross of Aleron campaign and Default++ era.
Former maintainer of Steelhive.
Post Reply