Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs

Execute specific function on error

A topic by Ronchiporc created 35 days ago Views: 30 Replies: 3
Viewing posts 1 to 4
(1 edit)

Hi,

I just purchased this extension and first of all , thanks a lot for this! Its exactly what i desperately needed.
But i was wondering it it would be to possible to add the option to execute one specific script immediately upon error, as a mix between catch_error_quit and catch_error_ignore mode ?  
So that if an error happens, this single script would be immediately executed , followed by closing the game in the same way that catch_error_quit does.

Ignoring an error until the error queue can be checked (ex at the end of the current step ) to execute custom actions seems too dangerous to me as a whole step with many unrelated functions would be executed in a potentially corrupted way.
Meanwhile quitting directly prevents me from attempting an emergency save of the game before it closes, which is all i want to do when a fatal error occurs.

If there was an option to execute a single script, i would be able to put all my emergency measures in it (saving the game) while being sure that these are the only actions executed between the error and the game closing; It would be an absolute life saver to have such functionality, like a new "catch_error_script" mode or something.
Would that ever be possible ?

Developer

I'm not sure if that would be possible, as that requires to figure out raw memory address of script_execute at runtime (assuming that it's a function at all) while having exactly zero information about it's structure or whereabouts.

However, it is not required to check for queued errors at the end of the step - you can check whenever, such as immediately after you do something that might have caused an error. Some people even made "try" / "catch" macros for GMS2 to store/check the current number of queued errors

I understand. That is unfortunate :( How about executing all "game end " events on error ? i assume its impossible for the same reason ? 

I remember a long time ago where game end events would still get executed on error, that was awesome as it prevented data loss almost every time. I can't remember when that changed...
Anyway thanks for the reply! Being able to hide these errors and autorestart is already a huge help.

Developer

Executing game events on error would be possible by simply doing a check on the end of the step and calling game_end - I tested a bit, and legacy-format errors (such as show_error, which will still fire Game End event) simply order the window to close itself and set a global flag so that you don't get any more error windows. I imagine that newer errors had been changed to quit instantly because you may not want to run any further code (including Game End) if the game state is potentially broken