Execute action before quitting game

  • #1, by i-c-gTuesday, 05. January, 18:44 3 weeks ago
    Here we go again with a "silly" thing I can't get: in the game properties I can register actions to execute at game starts, but I can't get how to execute actions BEFORE game ends.

    Basically I want to hook into the "Quit game" event, no matter how it is triggered, to save an autosave file right before the user exits the game, but I can't get where to register such and action.

    EDIT: I'd like to do the same to show a confirmation message, BTW, so I really hope there are options for this.

    I'm not afraid coding Lua scripts, should it be the only way to achieve my goal; actually I enjoy it more than using native actions... wink

    Ready to discover this can't be done... razz but I have the best hopes for this.
    Thanks in advance for any help guys!

    Newbie

    13 Posts


  • #2, by afrlmeTuesday, 05. January, 20:11 3 weeks ago
    There is no event for listening out for when game is being quit. Best thing to do would be to add the autosave at the beginning of each scene & just before changing scene, that way if they go to a menu then it will have saved on the previous scene.

    As soon as you tell the game to quit with the quit game action part or use the os.exit() Lua function the game is going to end immediately.

    Imperator

    6913 Posts

  • #3, by i-c-gTuesday, 05. January, 22:08 3 weeks ago
    So to my understanding, if - playing in a window - I press alt-F4 or the X button to close the window, there is no chance to ask the user if it's ok to really quit the game?

    This seems a bit of a flaw to me, pretty dangerous...

    Newbie

    13 Posts

  • #4, by afrlmeWednesday, 06. January, 12:02 3 weeks ago
    Err, not many things will ask you to confirm when you press alt + f4 as that's a windows thing. Try it, you will see that almost - if not - everything you try it on will immediately close without asking you to confirm.

    If someone presses alt + f4 together, then they obviously did it on purpose. As for clicking on the X button, I don't see anything in the luadocs page to popup a confirmation box, but maybe Simon knows of a method to catch it before it closes the application?

    Most people play games in fullscreen mode or fullscreen borderless window mode, so the min, max, close buttons are not usually visible to most people.

    Imperator

    6913 Posts

  • #5, by i-c-gWednesday, 06. January, 19:39 3 weeks ago
    Not trying to build up a case for this, but I think that being able to hook into the game shutdown (for waterver reason, related to user or to automate specific procedures), would be almost a must for an advanced engine like Visionaire.

    That said, not a big deal, as you said.
    It would have been great to provide an autosave on close, but I did it hooking into the game loop and checking both scene changes and configurable intervals. Not wonderful but better than nothing.

    Thanks for your kind help!
    Cheers

    Newbie

    13 Posts

Write post