How do I check if a menu is opened or closed?

From OHRRPGCE-Wiki
Jump to navigation Jump to search

So you have a made menu. It pops up on screen but when you want to close it you have error message? Well the name is error is called "invalid menu error"

There are two main reasons for that

1- You wrote a line like this one

 close menu (2)

because you though just like you use a figure to make open, you can use a figure to make it close. Therefore, Hspeak can't find the correct menu you're talking about

2-You correctly wrote

menu handle:= find menu ID (2)
close menu (menu handle)

because menu 2 is already closed when Hspeak.exe so again it cannot find and do what you want.

The source of this error is wrong menu handling. Menu are used with global variable. And one of function of the variable is that it can take two value true or false, 1 or 0. Keep in mind that

# menu handle == true means that the menu can be found and therefore is opened.  
# menu handle == false means that the menu cannot be found and therefore is closed 

To prevent this error we need to write with an if it so that we can check a returned value.

So the correct way to write it would be

menu handle:= find menu ID (4) #find menu and get it state (opened or not opened)
#if the command returns true then the menu is opened and we can close it or do other things later
if (menu handle == true) then, begin 
close menu (menu handle)

#other stuff here

end


If you include those last lines in your code, the error message will disappear. You specified that the command close menu can be executed only if the menu has been opened previously and is still currently opened.