I solved the problem with a global variable, but i don't know if it's the right way. I'm trying to create a menu that appears when a user click door and let the user choose a place to go (that is another map). So i did it that way:
1-I created the gui using Menu.lua as template
2-i wrote a code in the updatephysics of one object called computer that verifies if the user clicks the door (using camera:pick) and then shows the menu (that select the place to go)
3-i inserted a global variable in Main.lua called eventosGUI that stores the event
while EventQueue:Peek() do
local event
event = EventQueue:Wait()
eventosGUI = event
event = gamemenu:ProcessEvent(event)
end
4-then inside the updatephysics of the computer object, i compare eventosGUI.source with the button widget and if its true, i call changemapname = "name of the map"
But there is another problem. The cancel button that i put at the end of the menu is acting strangelly:
1-The player clicks the door
2-the menu opens normally
3- the player clicks the cancel button
4-the menu closes
5-the player click the door for the second time
6-the menu just flashes
7-the player click the door for the third time
8-the menu opens normally
So i solved this ploblem with a flag called corrigeQueue initially setted to false (but i don't know if it's the right way):
if eventosGUI ~= nil then
...
if eventosGUI.source == self.mudaLocalGui.botaoCancelar then
if not self.corrigeQueue then
self.paineldegui = false
self.mouse_padrao = false
self.jogador.script.modoAndar = true
self.mudaLocalGui:Hide()
janela:HideMouse()
self.corrigeQueue = true
else
self.corrigeQueue = false
end
end
eventosGUI = nil
end
I tried to flushkeys but it doesn't solved the problem, and i put a Debug:Assert(false, tostring(eventosGUI)) before showing the menu and it returns nil, but i know that the flashing is occurring because eventosGUI ~=nil and eventosGUI.source == self.mudaLocalGui.botaoCancelar returns true