Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

I want to rescue minor errors from closing the game

Okay, the topic title should explain the most of it, so I'm going to keep this short 'n sweet.

What I'm needing badly is some way to rescue the entire game session when a minor game-killing bug occurs (such as when stupid things happen like nilClass errors 'n stuff.) I'm not sure if its something I'd add to 'main' or if I'd have to redefine Errno::ENOENT or something. Obviously, I do still need the error to pop so I know to fix things accordingly, but I just don't want the small shit killing my game everytime I test it, it makes 5 minutes of work turn into 30 when I have to keep opening the game over 'n over.

Does anybody know of any good documents or a script/snippet that already does something like this, or how I could do it?
 
That's something I'd like to know too. But unfortunately, I think that the game is forced to be closed when the error pops up.
The only thing I've mannaged to do is displaying the error in a RGSS Window and exit after a couple of seconds.
 
Hmm... I'd probably have to alter all of the error-type classes and change their initialize... unless there's a quick 1 or 2 liner like the Hangup one that Zeriab sent me (not to rescue hangups, but to print the class/methods that are affected by it.)

Chances are though that I'd have to alter every error-type class to set a global to 'true', then when the error occurs it'd still do the error, but by setting the boolean to true then I'd later redefine Kernel exit and exit! to not occur if this global is true, then reset the global to nil. Just a theory, I'm gonna try it tomorrow when I have time, don't know if it'll work though...

I even tried to do a little research on the Errno::ENNONET (sp?) module in different sites like Ruby-lang 'n stuff, didn't really find anything useful yet.
 

Zeriab

Sponsor

A nilClass error can be a very serious bug from an error recovery point of view.
There are no golden way of doing it.
What you can do is to wrap the areas of interested in begin-rescue clasues and then pretend everything went fine.
In general it's easier to fix the error the closer you are to the problem.
You could for example change the main loop to:
Code:
  while $scene != nil
    begin
      $scene.main
    rescue Exception => err
      p err
      raise if Input.press?(Input::F8)
    end
  end

Then it will print the error and continue as if all is right unless you have F8 pressed.
As you can see might not be beneficial at all. The could be a lot of clutter and loads of graphical bugs.
On the other side it may just make you able to save the game.

It will under all circumstances be better if you can catch the error before that.
If you are experimenting with say a journal then you could make rescue clauses where the journal simply closes after telling you the error message and/or storing it in a log file.
There are also places where you might want permanent rescue clauses, namely places where they are to be expected.
For example when loading from and saving to save files. They can be read-only, right-only, locked, corrupted, not existing and so on. You can prepare for these errors and handle them gracefully so the player will simply get a message telling what the problem is and then be able to decide what else to do.
That is definitely better than the game simply crashes.

Designing a robust system is hard work and putting in too much defensive programming can effect the performance so you have to weigh the advantages against the disadvantages.
It is a case-by-case evaluation.

*hugs*
- Zeriab
 
Cool, that works just fine! Well, except for the fact that I can't simply exit out the game by clicking the X on the program anymore but I'll find out why later. I'm not really doing this for anybody but my own benefit, I wouldn't put this in a game or anything so I'm not worried about graphical errors or anything of that nature, just my own personal continuation of testing possibly errorous scripts. I tested it with this...

actor = 0
p actor.hp

The error was printed like I expected and wanted (with actor purposely being a Numeric and not a Game_Actor), and the game continued like I wanted, so yes this is basically all I needed, thank you Zeriab.

Unless I come up with a further related question, this topic is closed :thumb:
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top