How do I check if a menu is opened or closed?
So you have made a menu. It pops up on screen but when you want to close it you have error message? Well the name is error is "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. Even though you can create up up 32767 menus and each one has a figure and a name, the fact of a matter is that Hspeak can't find the correct menu you're talking about!
To avoid any possible error about an action on a given menu, you need remind Hspeak.Exe the number of the menu you want to act on.. just before you're acting on.
In this example it the command close menu, but it's the same when you want to activate or unactivate a bitset.
2-But to do it you need to write
menu handle:= find menu ID (2) close menu (menu handle)
If the menu is effectively on screen it will work smoothly.
But what if menu 2 is already closed? Hspeak.exe will again display an error message. So what should we do?
As you can see Menu are used with global variable. And one of function of the kind of variables 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
That's the same thing with slice collections. To prevent definitively any
error message from popping up we need add an if command.
This we can check a returned value before asking Hspeak.exe to do anything.
So the perfect/ 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
With this way of writing your code, you specified that the command close menu can be executed only if the menu has been opened previously and is still currently opened.
In any situations no error message will appear. Feel free to ask on the discord or on the forum if you problems to understand how the command works.