Post new topic    
Metal Slime
Send private message
How to get the selected item of a menu?i 
 PostSun Jan 18, 2015 5:25 am
Send private message Reply with quote
Hello!

I'm wondering if it is possible to get the currently selected item from a menu.
And not get it after it is choosen (that can be done by tags etc.), but just when it is selected.
I'd like to have the player choose something and display all the options on the screen.
The items are displayed as slices in a row, the selected item should move up and back down.

Plotscripting dictionary say about open menu fuction:
Quote:

open menu (ID, allow duplicate)
Opens the menu specified by ID. You can also use the constants defined in your HSI file in the form menu:name. The menu will be opened on top of any menus that are already open. The optional second argument allow duplicates can be true if you want to be able to open more than one copy of the same menu at the same time. The return value is a menu handle that you should store in a variable for use with other menu-related commands.


1) How can I get to know this retun value?
2) Is there a better way to get the selected (not yet choosen) menu?

Code:

#need this menu's return value and don't know how to get it! :(
   #PetMenu := open menu (3,0)
   
   variable(starfish)
   variable(jellyfish)
   variable(orangefish)
   variable(octopus)
   variable(guy)

    if (menu is open(PetMenu))
      (
      #number,palette
      starfish := load walkabout sprite (33, 41)
      jellyfish := load walkabout sprite (34, 42)
      orangefish := load walkabout sprite (35, 43)
      octopus := load walkabout sprite (36, 44)
      guy := load walkabout sprite (13, 1)
   
      put sprite(starfish, 20, 20)
      put sprite(jellyfish, 50, 20)
      put sprite(orangefish, 80, 20)
      put sprite(octopus, 110, 20)
      put sprite(guy, 140, 20)
      
      ChooseStar:= first menu item(PetMenu)
      ChooseJelly:= next menu item(PetMenu)
      ChooseOrange:= next menu item(PetMenu)
      ChooseOcto:= next menu item(PetMenu)
      ChooseGuy:= next menu item(PetMenu)
            
      if (selected menu item(PetMenu) == ChooseStar) then
         (
            #moves the slice 10 up
            move slice to (starfish, 10, 20,7)
            wait (3)
            move slice to (starfish, 20, 20,14)
            wait (3)
         )
      else if    
      (selected menu item(PetMenu) == ChooseJelly) then
         (
            #moves the slice 10 up
            move slice to (jellyfish, 40, 20,7)
            wait (3)
            move slice to (jellyfish, 50, 20,14)
            wait (3)
         )
      # add others here
      
      )
   else
         
      free sprite (starfish)
      free sprite (jellyfish)
      free sprite (orangefish)
      free sprite (octopus)
      free sprite (guy)


Thanks for you help! =D
If you have advice on how to 'handle' this better, please let me know. ;)
Metal King Slime
Send private message
 
 PostSun Jan 18, 2015 5:28 am
Send private message Reply with quote
I think your script is already correct? When you say

Code:

PetMenu := OpenMenu (3,0)


What you're really saying is

Code:

SetVariable ( PetMenu,OpenMenu (3,0) )


The variable PetMenu will be that returned value.

EDIT: As for the second part of the question, I have no idea how menus work and will leave that answer to someone better qualified.
Metal King Slime
Send private message
 
 PostSun Jan 18, 2015 6:06 am
Send private message Reply with quote
As Giz said, your script looks correct as long as you include "PetMenu := open menu (3,0)".

The way that you used "first menu item" and "next menu item" to check the selection is fine (provided that no menu items disappear based on tags!). But you're wondering, in order to check whether the selected menu item is the 3rd one, write:
menu item true slot (selected menu item (PetMenu) ) == 2
(You can also use "menu item slot" instead of "menu item true slot" as long as no menu items disappear based on tags. The "true" slot is the slot number as shown in the menu editor, while "menu item slot" returns the number of the menu item in the visible in-game menu)

You're missing the '(' or 'begin' after the 'else' at the bottom of your script.
Metal Slime
Send private message
 
 PostSun Jan 18, 2015 7:30 am
Send private message Reply with quote
Thanks for your answers. Grin

When I try using the "PetMenu := open menu (3,0)" part, the compiler says it's not recognized. (Not a script, variable, etc.)
By writing it that way A := B, it would be clear that A is a variable, right?

I added the missing begin to else as well. Smile
Metal King Slime
Send private message
 
 PostSun Jan 18, 2015 8:25 am
Send private message Reply with quote
Yes, A should be a variable. If you set up PetMenu somewhere as a variable, you'll be (probably) be right as rain.
Metal Slime
Send private message
 
 PostSun Jan 18, 2015 8:57 am
Send private message Reply with quote
It seems like I am not setting up a variable.

Code:
PetM := 0


I renamed PetMenu to PetM, so the word menu isn't used, just in case that could cause trouble.

I tried the script from Giz for setting a variable, and i tried this above from the plot scripting dictionary.
I still get the error message. Confused
Metal King Slime
Send private message
 
 PostSun Jan 18, 2015 9:06 am
Send private message Reply with quote
Look at what you're doing for Starfish, Jellyfish, etc. They're not throwing errors, but they're doing the same

Code:

Starfish := loadwalkaboutsprite (33,41)


stuff, right? It's trying to set the value of the variable Starfish to the number returned by the LoadWalkaboutSprite command. Notice how you declared that Starfish is the name of a variable with your

Code:

variable (Starfish)


You might try throwing a

Code:

variable (PetMenu)


in there, so that the game knows what PetMenu is.
Metal Slime
Send private message
 
 PostSun Jan 18, 2015 10:53 am
Send private message Reply with quote
Thanks Giz!
Now the script is compiling.

I do get an error when trying to start the script:
next menu item: invalid menu handle -1 Confused

So, I have to ask for help again.
Metal King Slime
Send private message
 
 PostSun Jan 18, 2015 5:50 pm
Send private message Reply with quote
Oh, I missed that.
Code:
 ChooseJelly:= next menu item(PetMenu)

should be
Code:
 ChooseJelly:= next menu item(ChooseStar)

and so on.

Also, rather than using 'PetMenu' everywhere you could use 'topmenu' instead, which is a handle for the topmost menu.
Display posts from previous: