Help filtering menu item based on sides unit & location

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.
User avatar
Legend_Rider
Posts: 35
Joined: June 20th, 2018, 4:51 pm

Help filtering menu item based on sides unit & location

Post by Legend_Rider »

Attempting to create a menu item that only shows up when a unit of the given side is located on specific terrain.
I have accomplished having the menu item show up when clicking on the unit, as well as when clicking on the terrain, but can't seem to combine the two :?

here's what I'm working with... :oops:

Code: Select all

# menu item stuffs...
    [filter]
        unit=$unit.side
        x,y=$x1,$y1
        [filter_location]
            terrain=G*
        [/filter_location]
    [/filter]
# /menu item stuffs...
Edit: I probably shouldn't be trying to work on WML in the late hours of the night... I just can't get my mind off of it! :lol:
Last edited by Legend_Rider on January 21st, 2021, 3:05 pm, edited 1 time in total.
User avatar
Straff
Posts: 85
Joined: September 27th, 2020, 2:53 pm

Re: Help filtering menu item based on sides unit & location

Post by Straff »

Untested:

Code: Select all

    [set_menu_item]
        [filter]
            side=$unit.side
        [/filter]
        id=test
        description="  "
        image="  "
        [show_if]
            [have_unit]
                x,y=$x1,$y1
            [/have_unit]
        [/show_if]
        [filter_location]
            terrain=G*
        [/filter_location]
        # stuff
    [/set_menu_item]
User avatar
Ravana
Forum Moderator
Posts: 2949
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: Help filtering menu item based on sides unit & location

Post by Ravana »

Example https://github.com/ProditorMagnus/Agele ... fg#L39-L69

Code: Select all

    [set_menu_item]
        [filter_location]
            terrain=G*
            [filter]
                side=4
            [/filter]
        [/filter_location]
     [/set_menu_item]
User avatar
Legend_Rider
Posts: 35
Joined: June 20th, 2018, 4:51 pm

Re: Help filtering menu item based on sides unit & location

Post by Legend_Rider »

Straff wrote: January 21st, 2021, 10:08 am Untested:

Code: Select all

    [set_menu_item]
        [filter]
            side=$unit.side
        [/filter]
        id=test
        description="  "
        image="  "
        [show_if]
            [have_unit]
                x,y=$x1,$y1
            [/have_unit]
        [/show_if]
        [filter_location]
            terrain=G*
        [/filter_location]
        # stuff
    [/set_menu_item]
Thank you, Straff!

That did the trick, it was mostly missing the "show if" tags.

Many thanks!
Last edited by Legend_Rider on January 22nd, 2021, 10:39 pm, edited 1 time in total.
User avatar
Legend_Rider
Posts: 35
Joined: June 20th, 2018, 4:51 pm

Re: Help filtering menu item based on sides unit & location

Post by Legend_Rider »

Trying to create a similar menu item (to which searching the forums and reading the wiki has only brought me so far.) :P

Creating a menu item that only shows up when X unit from a side is on X terrain adjacent to Z terrain

Here's one of my many attempts

Code: Select all

[set_menu_item]
    id=test
    description= _ "testing"
    [filter]
        side=$unit.side # not 100% sure if this is the best/correct key/value for this
    [/filter]
    [show_if] # only show if the following conditions are met?
        [have_unit] # if there is a unit
            unit=$unit.side # unit on your side? (idk if it's the right key, tested other keys to no avail)
            [filter_location]
                terrain=K*
            [/filter_location]
            [filter_adjacent_location]
                terrain=C*
            [/filter_adjacent_location]
        [/have_unit]
    [/show_if]

    [command] # a basic option to test the menu
        [message]
            side_for=$side_number # is this actually necessary? haven't tested it
            speaker=narrator
            [option]
                message= _ "Cancel"
                speaker=narrator
            [/option]
        [/message]
    [/command]
    
[/set_menu_item]
Edit: clarifications
Last edited by Legend_Rider on January 24th, 2021, 10:56 pm, edited 1 time in total.
vghetto
Posts: 755
Joined: November 2nd, 2019, 5:12 pm

Re: Help filtering menu item based on sides unit & location

Post by vghetto »

Not sure what you need the side thing for.
Try the following and see if it's what you want:

Code: Select all

 [set_menu_item]
     id=test
     description= _ "testing"
     [show_if]
         [have_unit] # if there is a unit 
             x,y=$x1,$y1
             #side=1  # Set the side explicitly, or leave out if it applies to all sides.
             #side=$side_number
             [filter_location]
                 terrain=K*
                 [filter_adjacent_location]
                     terrain=C*
                 [/filter_adjacent_location]
             [/filter_location]
         [/have_unit]
     [/show_if]
     [command] # a basic option to test the menu
         [message]
             speaker=$unit.id
             message= _ "Hi"
         [/message]
     [/command]
 [/set_menu_item]
Edit:
If it's for MP then use side=$side_number
User avatar
Legend_Rider
Posts: 35
Joined: June 20th, 2018, 4:51 pm

Re: Help filtering menu item based on sides unit & location

Post by Legend_Rider »

vghetto wrote: January 23rd, 2021, 7:01 am

Code: Select all

 [set_menu_item]
     id=test
     description= _ "testing"
     [show_if]
         [have_unit] # if there is a unit 
             x,y=$x1,$y1
             #side=1  # Set the side explicitly, or leave out if it applies to all sides.
             #side=$side_number
             [filter_location]
                 terrain=K*
                 [filter_adjacent_location]
                     terrain=C*
                 [/filter_adjacent_location]
             [/filter_location]
         [/have_unit]
     [/show_if]
     [command] # a basic option to test the menu
         [message]
             speaker=$unit.id
             message= _ "Hi"
         [/message]
     [/command]
 [/set_menu_item]
Edit:
If it's for MP then use side=$side_number
Thank you vghetto!
It is for MP use, (forgot to specify, sorry)
This solved my little puzzle.
Only thing I need to do now is figure out how to set the menu to show up adjacent to the unit rather than on the unit.
vghetto
Posts: 755
Joined: November 2nd, 2019, 5:12 pm

Re: Help filtering menu item based on sides unit & location

Post by vghetto »

Legend_Rider wrote: January 24th, 2021, 10:53 pm Only thing I need to do now is figure out how to set the menu to show up adjacent to the unit rather than on the unit.
The menu shows up where you right click. It is unclear to me what you'd like to do exactly. Could you clarify?
User avatar
Legend_Rider
Posts: 35
Joined: June 20th, 2018, 4:51 pm

Re: Help filtering menu item based on sides unit & location

Post by Legend_Rider »

As of right now, the context menu shows the option when you have your mouse over the unit on K* terrain, I am working to make the menu show up when you have your mouse over C* terrain and there’s an adjacent unit on K* terrain.

I hope that clarifies. :)
vghetto
Posts: 755
Joined: November 2nd, 2019, 5:12 pm

Re: Help filtering menu item based on sides unit & location

Post by vghetto »

I didn't test this, but give it a try.

Code: Select all

 [set_menu_item]
     id=test
     description= _ "testing"
     [show_if]
         [have_unit] # if there is a unit 
             x,y=$x1,$y1
             side=$side_number
             [filter_location]
                 terrain=C*
                 [filter_adjacent_location]
                     terrain=K*
                     [filter]
                     [/filter]
                 [/filter_adjacent_location]
             [/filter_location]
         [/have_unit]
     [/show_if]
     [command] # a basic option to test the menu
         [message]
             speaker=$unit.id
             message= _ "Hi"
         [/message]
     [/command]
 [/set_menu_item]
User avatar
Straff
Posts: 85
Joined: September 27th, 2020, 2:53 pm

Re: Help filtering menu item based on sides unit & location

Post by Straff »

Should there be a unit on the C* hex, or should the C* hex be empty?
User avatar
Legend_Rider
Posts: 35
Joined: June 20th, 2018, 4:51 pm

Re: Help filtering menu item based on sides unit & location

Post by Legend_Rider »

I’ll give it a try when I can, the C* hex should be empty.

Whoops, trying to navigate the website on mobile for the first time :P
I kinda made an oopsie :lol:
Last edited by Legend_Rider on January 25th, 2021, 7:17 pm, edited 1 time in total.
User avatar
Legend_Rider
Posts: 35
Joined: June 20th, 2018, 4:51 pm

Re: Help filtering menu item based on sides unit & location

Post by Legend_Rider »

vghetto wrote: January 25th, 2021, 5:36 pm I didn't test this, but give it a try.

Code: Select all

 [set_menu_item]
     id=test
     description= _ "testing"
     [show_if]
         [have_unit] # if there is a unit 
             x,y=$x1,$y1
             side=$side_number
             [filter_location]
                 terrain=C*
                 [filter_adjacent_location]
                     terrain=K*
                     [filter]
                     [/filter]
                 [/filter_adjacent_location]
             [/filter_location]
         [/have_unit]
     [/show_if]
     [command] # a basic option to test the menu
         [message]
             speaker=$unit.id
             message= _ "Hi"
         [/message]
     [/command]
 [/set_menu_item]
I’ll give it a try when I can :)

Straff wrote: January 25th, 2021, 5:51 pm Should there be a unit on the C* hex, or should the C* hex be empty?
the C* hex should be empty.
vghetto
Posts: 755
Joined: November 2nd, 2019, 5:12 pm

Re: Help filtering menu item based on sides unit & location

Post by vghetto »

Ah, then my example won't do what you want.

This might, I didn't test this either :whistle:

Code: Select all

 [set_menu_item]
     id=test
     description= _ "testing"
     [show_if]
         [have_location]
                 x,y=$x1,$y1
                 terrain=C*
                 [not]
                       [filter]
                       [/filter]
                 [/not]
                 [filter_adjacent_location]
                     terrain=K*
                     [filter]
                     [/filter]
                 [/filter_adjacent_location]
         [/have_location]
     [/show_if]
     [command] # a basic option to test the menu
         [message]
             speaker=$unit.id
             message= _ "Hi"
         [/message]
     [/command]
 [/set_menu_item]
User avatar
Legend_Rider
Posts: 35
Joined: June 20th, 2018, 4:51 pm

Re: Help filtering menu item based on sides unit & location

Post by Legend_Rider »

vghetto wrote: January 25th, 2021, 7:37 pm Ah, then my example won't do what you want.

This might, I didn't test this either :whistle:

Code: Select all

 [set_menu_item]
     id=test
     description= _ "testing"
     [show_if]
         [have_location]
                 x,y=$x1,$y1
                 terrain=C*
                 [not]
                       [filter]
                       [/filter]
                 [/not]
                 [filter_adjacent_location]
                     terrain=K*
                     [filter]
                     [/filter]
                 [/filter_adjacent_location]
         [/have_location]
     [/show_if]
     [command] # a basic option to test the menu
         [message]
             speaker=$unit.id
             message= _ "Hi"
         [/message]
     [/command]
 [/set_menu_item]
That did it!! :shock: :D
Thanks a bundle!

May I ask how the "empty" [filter] tags work?
something I've seen before but don't fully understand ^_^

Edit: as a side note, I did add a way that limits the menu to only show when it's your unit on the terrain.
Because I'm using village as the terrain, it was very simple to do using "owner_side=$side_number"
Last edited by Legend_Rider on January 28th, 2021, 2:13 am, edited 3 times in total.
Post Reply