Main Menu
  • Welcome to The RPG Maker Resource Kit.

Nil fix snippet

Started by Tuomo L, September 16, 2012, 03:52:14 PM

0 Members and 1 Guest are viewing this topic.

Tuomo L

Nil Fix Snippet

Here's a small thing I wanted to share, which I've come to realize when playing around and trying out few scripts and fooling around in the editor. In many cases, a no method error is caused by Nilclass error due to the fact that the script is calling for Nil class instead of Empty Class, which may cause a nomethod error as there's not a defined NilClass. This snippet should remove many incompatibility errors and crashes due to Nilclass not having an empty method. On few test runs, it's had good results so I thought I'd share it. I've not had any extensive testings but it should be plug&play.

Screenshots

Not applicable

How to Use
For optimal performance, put this bellow all other scripts you may have and above main process.

Demo

Not really needed...

Script


class NilClass
    def empty?
        true
    end
end


FAQ
Post question and answers to common question here in the following format:

Q: Can I use this in comercial project?
A: You can use it in anything, it's more of a snippet than script so...
Q: Will this work in *insert another rpgmaker or engine here*?
A: I only have acess to RPGMaker Ace so I can't say for sure.

Credit and Thanks
No need to credit me or anything, free to use and all that goodness.

Thank you Jesus from the beginning

Wiimeiser

Hopefully this will fix the bug in Yanfly's Adjust Limits script where setting an individual actor's max level above 98 causes a crash...

Tuomo L

You can try. I'd like to hear a report from if it does, it's at least fixe one script's functionality so far. From what I tried, it did fix Yanfly System Options randomly crashing as well with this title script.  :blizj:

http://www.rpgmakervxace.net/topic/825-title-screen-aqua/


D&P3

I'm surprised that hasn't caused you a wide range of issues.

NilClass means that something is either missing or not initialised.
If you're simply neutralising the error message like this, I'd imagine that would cause Undefined Behaviour.
All of my scripts are totally free to use for commercial use. You don't need to ask me for permission. I'm too lazy to update every single script post I ever made with this addendum. So ignore whatever "rule" I posted there. :)

All scripts can be found at: https://pastebin.com/u/diamondandplatinum3

Tuomo L

Quote from: D&P3 on September 16, 2012, 05:10:00 PM
I'm surprised that hasn't caused you a wide range of issues.

NilClass means that something is either missing or not initialised.
If you're simply neutralising the error message like this, I'd imagine that would cause Undefined Behaviour.

On the contrary, without this one script I was using did not work at all. Even when loading properly it would cause problems in other places. After the snippet, everything works as they should.

modern algebra

#5
Well, it will "work" in cases where a script checks if x is empty when there is a possibility that x is nil, when x is not operated on if empty? is true, and when the script still functions whether x is nil or not. However, for many scripts on which this could potentially operate, those conditions won't be satisfied, and this "fix" won't simply hide error messages, it will prevent code from running that has to run in order for the script to function. In the result, the script will behave unexpectedly without telling you why, and that's really, really bad. To be sure, the project would crash without this "fix", but with this "fix" any scripter who is looking to diagnose the errors in his or her logic will be at a serious disadvantage.

As a scripter, I would never want something that suppresses error messages, since error messages disclose failures in my logic that should be corrected, not ignored. In other words, error messages disclose errors, but they aren't themselves errors, and they don't need to be "fixed".

That said, I can understand why some non-scripters might want something like this for situations where the logical error is otherwise harmless, but I will caution that if you ever encounter any errors or lack of function in any other script you use, delete this "fix" before asking a scripter for help. In general, I think you're better off to ask for help with a script that's throwing errors, and not to just put this code in and hope it's a situation where the actual error in the script is otherwise harmless.

Still, thank you for sharing.

Wiimeiser

Example: Adjust Limits is broken with regards to actor levels. Use even one note tag and the game won't even start.

Tuomo L

#7
Quote from: modern algebra on September 16, 2012, 09:28:21 PM
Well, it will "work" in cases where a script checks if x is empty when there is a possibility that x is nil, when x is not operated on if empty? is true, and when the script still functions whether x is nil or not. However, for many scripts on which this could potentially operate, those conditions won't be satisfied, and this "fix" won't simply hide error messages, it will prevent code from running that has to run in order for the script to function. In the result, the script will behave unexpectedly without telling you why, and that's really, really bad. To be sure, the project would crash without this "fix", but with this "fix" any scripter who is looking to diagnose the errors in his or her logic will be at a serious disadvantage.

As a scripter, I would never want something that suppresses error messages, since error messages disclose failures in my logic that should be corrected, not ignored. In other words, error messages disclose errors, but they aren't themselves errors, and they don't need to be "fixed".

The scripter had abandoned the said script and it's no longer supported, the last update was in January. There's not anything wrong in the script per say but it is causing this bug for some reason. With the snippet, the script now functions and one can enjoy it without the errors its causing. :o

modern algebra

#8
Regardless, a specific solution for that script is better than a general solution which makes errors in other scripts hard to detect. It would be better just to post a topic in Scripts asking for help with the specific script.

If you are getting a NoMethodError, it is because you do not know what class of object you are operating on (in this case). Defining the missing methods in the classes you do not want to be operating on is not a viable or rational fix. As an analogy, let's say you want to call Mark but select the wrong contact and call Mary instead. The best way to fix this problem would be to hang up and call Mark, but what this script does is rename Mary to Mark in your Contacts List; you are still talking to Mary and not Mark. Sometimes this might not cause a problem (for instance, if you were calling Mark for IT help and Mary is also an IT person), but in the majority of cases, Mary is not a useful substitute for Mark and it is better not to be calling Mary when you want to be calling Mark.

Tuomo L

But what about the script that's not working without this? Should I just remove it?  ???

modern algebra

No, you should post a topic in Scripts identifying the script and asking for help. It's more likely an incompatibility than a straight error, so it might help if you also recreate the error in a new project and upload it.