Create menu in mod

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
LordAndrew
Posts: 23
Joined: April 1st, 2018, 3:09 am
Location: Russia

Create menu in mod

Post by LordAndrew »

Hi ! I want to create menu box in game. How to make a return to the previous menu ?
Below I'll give you the code of what I want

Code: Select all

[message]
speaker=narrator
caption="tutle"
message="You are in menu"

[option]
message=" "Return to the game"
[/option]

[option]
message="choose1"
[/option]

[option]
message="choose2"
[/option]

[option]
message="choose3"
[command]
[message]
[option]
message="return previous menu"
[/option]
[option]
[command]
[message]
message="choose3.1"
[/command]
[/option]
[/message]
[/command]
[/option]
[/message]
[/command]
[/option]
How call dialog message "you are in menu" ? :oops:
Last edited by Ravana on April 3rd, 2018, 5:49 pm, edited 1 time in total.
Reason: Use [code] without [spoiler]
User avatar
Ravana
Forum Moderator
Posts: 2949
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: Create menu in mod

Post by Ravana »

Loop or fire_event might be easiest to use.
User avatar
LordAndrew
Posts: 23
Joined: April 1st, 2018, 3:09 am
Location: Russia

Re: Create menu in mod

Post by LordAndrew »

How it can help me ? I dont use unit or attack. its only text dialog NO id NO name
https://wiki.wesnoth.org/InternalAction ... e_event.5D
(Version 1.13.6 and later only)
I dont know how it loop. put menu in menu in menu in menu...... :D
User avatar
Ravana
Forum Moderator
Posts: 2949
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: Create menu in mod

Post by Ravana »

For loop examples most of addons with shop should work, with fire_event I have done it as https://github.com/ProditorMagnus/Agele ... #L168-L175 https://github.com/ProditorMagnus/Agele ... nu.cfg#L76
User avatar
LordAndrew
Posts: 23
Joined: April 1st, 2018, 3:09 am
Location: Russia

Re: Create menu in mod

Post by LordAndrew »

How it work ? If use [event] i dont see my menu and how it can work if [fire_event] support name and id only for version 1.13.6 and later ? nonsense and untruth. Maby this ageless mod (menu) work only 1.11 version or brake ?
User avatar
Ravana
Forum Moderator
Posts: 2949
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: Create menu in mod

Post by Ravana »

"Optional" is devfeature not name. You can try that menu out, though with 1.13 it is quite difficult since it changed how deselecting unit works.
User avatar
LordAndrew
Posts: 23
Joined: April 1st, 2018, 3:09 am
Location: Russia

Re: Create menu in mod

Post by LordAndrew »

In version 1.12 it is impossible to make a return to the previous menu as it is easier ? Not overwriting everything. How can I add ID or NAME to tag [option], [command], ? Tag [command] can call previous [option] ?
Then developers need to add in the new version ID and NAME (class,variable) for all tags. As in the php javascript and other
User avatar
ForestDragon
Posts: 1769
Joined: March 6th, 2014, 1:32 pm
Location: Ukraine

Re: Create menu in mod

Post by ForestDragon »

menu loops can be made like this (to get the desired results, you might want to put [while]/[do] loops into eachother):

Code: Select all

        [set_variable]
            name=shoppingdone
            value=no
        [/set_variable]
        [while]
            [variable]
                name=shoppingdone
                equals=no
            [/variable]
            [do]
                [message]
                    speaker=narrator
                    message= _ "menu text"

                    [option]
                        message= _ "exit menu (or enter previous sub-menu)"
                        [command]
                            [set_variable]
                                name=shoppingdone
                                value=yes
                            [/set_variable]
                        [/command]
                    [/option]
                    [option]
                        message=  {MENU_IMG_TXT "attacks/bow-short.png" _"menu option (looped)"}
                        [command]
#insert menu content
                        [/command]
                    [/option]
                [/message]
            [/do]
        [/while]
My active add-ons: The Great Steppe Era,XP Bank,Alliances Mod,Pestilence,GSE+EoMa,Ogre Crusaders,Battle Royale,EoMaifier,Steppeifier,Hardcoreifier
My inactive add-ons (1.12): Tale of Alan, The Golden Age
Co-creator of Era of Magic
User avatar
Sapient
Inactive Developer
Posts: 4453
Joined: November 26th, 2005, 7:41 am
Contact:

Re: Create menu in mod

Post by Sapient »

And this would be how to do it with fire_event :

Code: Select all

      #define SHOPMENU NUM
        [fire_event]
          name=shopmenu {NUM} 
        [/fire_event]
      #enddef
      [event]
        name=shopmenu 1
        first_time_only=no
        [message]
          speaker=narrator
          message= _ "Welcome to the Shop! This is a Menu!"
          [option]
            message= _ "exit menu"
            [command]
            [/command]
          [/option]
          [option]
            message=  {MENU_IMG_TXT "attacks/bow-short.png" _"menu option (and keep shopping)"}
            [command]
# TO DO: do something here
              {SHOPMENU 1}
# then keep shopping!
            [/command]
          [/option]
        [/message]
      [/event]
http://www.wesnoth.org/wiki/User:Sapient... "Looks like your skills saved us again. Uh, well at least, they saved Soarin's apple pie."
User avatar
LordAndrew
Posts: 23
Joined: April 1st, 2018, 3:09 am
Location: Russia

Re: Create menu in mod

Post by LordAndrew »

ForestDragon
Yes its work ! But to make this functional for subcategories in categories i cant.

Sapient.
Its goodly but no events for triggering tag [event] for this reason it will never work. If i use this construction me need put [event] in [event] i think its slow down game.
User avatar
Sapient
Inactive Developer
Posts: 4453
Joined: November 26th, 2005, 7:41 am
Contact:

Re: Create menu in mod

Post by Sapient »

Don't worry about efficiency concerns... this is menu display code, not heavy computation. It's quite simple to make another menu, "shopmenu 2", using a separate event, then to call that from the first menu. Why don't you try it? If you have trouble then I'd be glad to help.
http://www.wesnoth.org/wiki/User:Sapient... "Looks like your skills saved us again. Uh, well at least, they saved Soarin's apple pie."
User avatar
LordAndrew
Posts: 23
Joined: April 1st, 2018, 3:09 am
Location: Russia

Re: Create menu in mod

Post by LordAndrew »

Ok. And how i can call this [event] name=menu ?
User avatar
ForestDragon
Posts: 1769
Joined: March 6th, 2014, 1:32 pm
Location: Ukraine

Re: Create menu in mod

Post by ForestDragon »

LordAndrew wrote: April 11th, 2018, 11:47 am Ok. And how i can call this [event] name=menu ?
by putting a [fire_event] into [command]
My active add-ons: The Great Steppe Era,XP Bank,Alliances Mod,Pestilence,GSE+EoMa,Ogre Crusaders,Battle Royale,EoMaifier,Steppeifier,Hardcoreifier
My inactive add-ons (1.12): Tale of Alan, The Golden Age
Co-creator of Era of Magic
User avatar
LordAndrew
Posts: 23
Joined: April 1st, 2018, 3:09 am
Location: Russia

Re: Create menu in mod

Post by LordAndrew »

I can bind hotkeys ? if i use [event] in menu . For fast access separate (individual) menu
User avatar
ForestDragon
Posts: 1769
Joined: March 6th, 2014, 1:32 pm
Location: Ukraine

Re: Create menu in mod

Post by ForestDragon »

LordAndrew wrote: April 11th, 2018, 12:02 pm I can bind hotkeys ? if i use [event] in menu . For fast access separate (individual) menu
it can be done by putting something like this into the [set_menu_item]:

Code: Select all

        [default_hotkey]
            key=r
        [/default_hotkey]
My active add-ons: The Great Steppe Era,XP Bank,Alliances Mod,Pestilence,GSE+EoMa,Ogre Crusaders,Battle Royale,EoMaifier,Steppeifier,Hardcoreifier
My inactive add-ons (1.12): Tale of Alan, The Golden Age
Co-creator of Era of Magic
Post Reply