First, I know that it's a bad practice to call an exit function to quit an app on mobile but I'm more interested in desktop and web games.
I saw in the documentation that the Application:exit() call is only available on Android. Is it still the case or is it an old description of that method?
I want to be able to quit my game with some kind of input (for example from a menu option or by pressing Escape key or a gamepad back button). How would I do that?
local function onKeyDown(self, event)
local ESCAPE_KEY = 27
if event.realCode == ESCAPE_KEY then
Application:exit()
end
end |
Would it do the job?
Comments
Gideros has macros (they can act as constants) so they don't take up valuable variable space, also they may work a few cycles faster.
https://deluxepixel.com
don't forget to save states to file if necessary, before quitting.
Fragmenter - animated loop machine and IKONOMIKON - the memory game
Those macros are awesome! Didn't knew that!
@keszegh Yeah! I'll have to be watchful of that!
Likes: SinisterSoft
Likes: SinisterSoft
Fragmenter - animated loop machine and IKONOMIKON - the memory game
However, @SinisterSoft 's advice was a good one for me.
Likes: SinisterSoft
Player.
However, the escape key code from previous answers doesn't work at all. When I trace it in the console, the Escape key has a weird realCode. I thought it was 27 according to many charts on the web (just an assumption since there is no documentation for that key and many others). When I traced realCode values in the console, the Escape key gave me the value 16777216. Number keys (up the letter keys not the numpad ones) gave me weird numbers too.
I have a french keyboard by the way.
I don't get it at all.
maybe the button is stuck shift + m +h
https://play.google.com/store/apps/developer?id=razorback456
мій блог по гідерос https://simartinfo.blogspot.com
Слава Україні!
Would you be kind to try it on yours and tell me what are the values you get?
try this way
https://play.google.com/store/apps/developer?id=razorback456
мій блог по гідерос https://simartinfo.blogspot.com
Слава Україні!
Fragmenter - animated loop machine and IKONOMIKON - the memory game
@keszegh Where did you found this constant? The documentation doesn't lists it. However, with this, it seems to work.
What is the difference between keycode and realCode properties? It seems I can compare the keyCode with the right constant but not the realCode.
F1 to F12 gives realCodes of 16777264...16777275 but keyCodes of 0.
I think I'm wrong somewhere.
realCode: (number) real keyCode underneath
https://play.google.com/store/apps/developer?id=razorback456
мій блог по гідерос https://simartinfo.blogspot.com
Слава Україні!
Here is my code :
Edit : When I export to Windows, it says something different : index '__userdata' cannot be found.
where KeyCode.ESC comes from i don't know, there are some undocumented things which only exist in hidden forum topics, but probably it is anyway only a constant equal to 27.
Fragmenter - animated loop machine and IKONOMIKON - the memory game
Application:exit()application:exit()
Likes: SinisterSoft
https://play.google.com/store/apps/developer?id=razorback456
мій блог по гідерос https://simartinfo.blogspot.com
Слава Україні!
https://deluxepixel.com
Likes: MoKaLux
Fragmenter - animated loop machine and IKONOMIKON - the memory game
@keszegh Indeed! French keyboards are a nightmare to code!
Likes: SinisterSoft
https://play.google.com/store/apps/developer?id=razorback456
мій блог по гідерос https://simartinfo.blogspot.com
Слава Україні!
Likes: oleg
Is it possible in gideros to handle the button close of a window app?
For example if the user is on the menu screen and clicks the close button (x) then the app closes. But if the user is on the level 1 screen and presses the close button then the app goes to menu screen?
The KeyCode.ESC works but I would like to push it a little bit further. Thank you.
Likes: SinisterSoft
Likes: Apollo14
https://deluxepixel.com
To introduce myself a little bit, I am coming mostly from java (I did a little bit of everything as a hobby). Now I am learning gideros (and lua). I am making some progress and when I read the doc (which can be very old) I stumble upon some articles/tutos that can be enhanced. My contribution will be small at the beginning but should increase!?
Likes: SinisterSoft
Likes: MoKaLux
https://deluxepixel.com