How to make RMMV ignore error and just proceed?

vectorinox

Airport Luggage
Veteran
Joined
Jun 20, 2016
Messages
45
Reaction score
9
First Language
Singlish
Primarily Uses
As an example, this is one of my code that counts every events within 3 tiles of the player.

try { for (var i =1; i<300; i++)


{ if (Math.abs($gameMap.events().x - $gamePlayer.x) <= 3)


{ if (Math.abs($gameMap.events().y - $gamePlayer.y) <= 3)


{ $gameVariables.setValue(14, $gameVariables.value(14) + 1)


}}}} catch(err){}
 


Now the code doesn't matter, but what really annoys me that the game sometimes randomly throw this error:


Untitled-1.jpg


Which is the reason I include "try { } catch(err) { }" in the code, so it will just proceed instead of crashing.


But this too, apply to all codes in the game. Sometime an error appear and I can't figure out why or where. So it is best to just ignore it (not the best option, I know).


But placing the "try { } catch(err) { }" line in every code in the game is tedious and not elegant. 


So is there a line in the RMMV error handling that can be modified to ignore any errors and just proceed?
 
Last edited by a moderator:

bgillisp

Global Moderators
Global Mod
Joined
Jul 2, 2014
Messages
13,522
Reaction score
14,255
First Language
English
Primarily Uses
RMVXA
See if there is a rescue command instead. I did this in ACE with a rescue catch which forces the program to run the code after the rescue if an error is thrown. Though, it has to be added at every point in the engine you wish it to run, which is a disadvantage. Still, see if MV has an JavaScript equivalent.


(As for the error you mentioned, an undefined error means the variable doesn't exist at that point in time. I notice your code is checking for events 1 - 300, but makes no allowance for if events 1 - 300 even exist! That is probably the source of your error).
 
Last edited by a moderator:

LTN Games

Indie Studio
Veteran
Joined
Jun 25, 2015
Messages
704
Reaction score
631
First Language
English
Primarily Uses
RMMV
Just  perform a check to see if it's undefined and if it is undefined then don't run reest of the code or vice versa, it's up to you.

Code:
      for (var i = 1; i < 300; i++) {
        if (typeof $gameMap.events().x === 'undefined') {
          break
         // break will stop the loop you can use 'continue' to skip to next iteration
        }
        if (Math.abs($gameMap.events().x - $gamePlayer.x) <= 3) {
          if (Math.abs($gameMap.events().y - $gamePlayer.y) <= 3) {
            $gameVariables.setValue(14, $gameVariables.value(14) + 1)
          }
        }
      }
 
Last edited by a moderator:

Andar

Veteran
Veteran
Joined
Mar 5, 2013
Messages
31,355
Reaction score
7,668
First Language
German
Primarily Uses
RMMV
Aside from the answers above, there is one much more important question:


Why would you even think of ignoring and hiding error messages?????


If there is an error message, then you're doing something wrong. Hiding that error message does not remove the error itself - and very often an error has more consequences than just the obvious.


If you continue to hide errors, your game will basically be impossible to get bug-free, no matter how much betatesting you try - simply because sooner or later the mess you create by hiding errors will collapse on you.


That reminds me of a story that I read about, about someone and his car repairs. One day he got a warning lamp for oil problems. He didn't do anything about it and continued to drive - but the red light was irritating, so he used black tape to cover it.


One guess what happened later?


Since that was not the only point where he used those types of "repairs", the car broke down a lot faster than it should have based on age...
 

bgillisp

Global Moderators
Global Mod
Joined
Jul 2, 2014
Messages
13,522
Reaction score
14,255
First Language
English
Primarily Uses
RMVXA
Andar brings up a good point too. You always want to find the cause, not hide the error. What I suggested with the rescue idea works best for say missing file errors (which is what I use them for), where it plays a dummy file that is used nowhere else just so the game keeps going. Though, at some point, you then have to figure out why the file is missing and fix it, unless you want something odd like all your SE's to be wolf howls in the game.
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,098
Reaction score
13,704
First Language
English
Primarily Uses
RMMV
You don't ignore errors - you look and see what's causing them, and you fix it.


If you get an error, don't make the assumption that you know best and that the error is incorrect.  There is a 100% chance that YOU have done something wrong.  If you find a way to stop the error message appearing and continue, you're going to end up with logic issues where things are not behaving as you expect, but not falling over, so you have no idea where the problem is.


Look at your code - it's wrong.  There is no such thing as $gameMap.events().x because $gameMap.events() is an array and arrays don't have a property called x.  Same thing with the next line.  You probably intended to use your iterator in there to get that event.  Interestingly, the error message is indicating that $gameMap.events() itself is undefined.  This could mean your script is being called out of context.  What class have you defined it in?  What calls it?  You'd probably want it to be in Game_Player, but it seems it might be running when the map hasn't even been created, or at least before events are added - just as the game is loading or something.  So that's a second thing you might want to fix.


The other thing you can do, if you just can't figure it out, is to post the script on the forum along with the error message you're getting.  Don't just ignore them or try to skip them.
 
Last edited by a moderator:

SimProse

Veteran
Veteran
Joined
Jul 9, 2016
Messages
371
Reaction score
202
First Language
English
Primarily Uses
Aside from the answers above, there is one much more important question:


Why would you even think of ignoring and hiding error messages?????


This. This is true of any programming language...errors are there for a reason. Often variables or functions won't work properly if errors are happening, regardless of whether they're "hidden" or not.
 

vectorinox

Airport Luggage
Veteran
Joined
Jun 20, 2016
Messages
45
Reaction score
9
First Language
Singlish
Primarily Uses
Look at your code - it's wrong.  There is no such thing as $gameMap.events().x because $gameMap.events() is an array and arrays don't have a property called x.
Sorry, sorry. It was $gameMap.events(). square brackets with i inside x originally (you cannot type that in this text box for whatever reason). Also I made the code to create error on purpose to test error handling (that "try catch" function).

Why would you even think of ignoring and hiding error messages?????
Nah, I don't want to hide it. I just want to ignore the error first because I don't know how to fix it (yet).


Though I'm well aware it's a horrible idea to ignore the error.


During test, run whenever an error message appear, the game froze and don't allow you to proceed right? That's my point, I wanted  RMMV to just show the error on the console log instead of freezing the game and showing it on a black screen, because I want to keep playing to reproduce the error instead of having to close the game and go back to the editor.


 
 
Last edited by a moderator:

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,098
Reaction score
13,704
First Language
English
Primarily Uses
RMMV
The thing is, if the game encounters an error, it HAS to stop and tell you about it.  You NEED to fix it before you can proceed, because something has gone wrong and whatever happens after that point is not going to be what SHOULD happen after that point.


Please copy and paste your code here, exactly as it is in your game.  Even what you put above as "what it really was" is incorrect.  We need to see what you HAVE, not what you retype, as you are not typing it exactly the same as you have in your game, which makes it hard for us to help you.
 

Andar

Veteran
Veteran
Joined
Mar 5, 2013
Messages
31,355
Reaction score
7,668
First Language
German
Primarily Uses
RMMV
 $gameMap.events(). square brackets with i inside x originally (you cannot type that in this text box for whatever reason).


but you can - []{} all kind of symbols and signs work here - if they don't work for you it is an error on your computer
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

How many parameters is 'too many'??
Yay, now back in action Happy Christmas time, coming back!






Back in action to develop the indie game that has been long overdue... Final Fallacy. A game that keeps on giving! The development never ends as the developer thinks to be the smart cookie by coming back and beginning by saying... "Oh bother, this indie game has been long overdue..." How could one resist such? No-one c
So I was playing with filters and this looked interesting...

Versus the normal look...

Kind of gives a very different feel. :LZSexcite:
To whom ever person or persons who re-did the DS/DS+ asset packs for MV (as in, they are all 48x48, and not just x2 the pixel scale) .... THANK-YOU!!!!!!!!! XwwwwX

Forum statistics

Threads
105,849
Messages
1,016,977
Members
137,563
Latest member
cexojow
Top