NoMethodError In a script I use.

Hello, I've been trying for quite a few days, to get this script to work, it tells me "Script 'Item Effects' Line 213: NoMethodError occurred
 Error occurred, check the debug console for more information.


here is the debug console Crash occurs at 231


https://gist.github.com/anonymous/4f29b1b51013721cb08ec2c35ee103c9


Here is the Script in question


https://gist.github.com/anonymous/2bbc1a792bf3baef2f80dabb3a5f6828


If anybody could point me in the right direction to fix this, it would help greatly.
Did you start a new game after installing that script or did you load an old savefile?


In 95% of all cases such errors are caused by savefiles that have become incompatible due to the added script, you NEED to start a new game for those scripts.


If you started a new game, then that is an incompatibility with one of your other scripts and you need to disable them one after another until you find the conflicting script, then try to find a compatibility patch.
Did you start a new game after installing that script or did you load an old savefile?


In 95% of all cases such errors are caused by savefiles that have become incompatible due to the added script, you NEED to start a new game for those scripts.


If you started a new game, then that is an incompatibility with one of your other scripts and you need to disable them one after another until you find the conflicting script, then try to find a compatibility patch.

New file, but it's strange because the script's i'm using were set up and ordered by the script dev. guess I can try that.
Did you start a new game after installing that script or did you load an old savefile?


In 95% of all cases such errors are caused by savefiles that have become incompatible due to the added script, you NEED to start a new game for those scripts.


If you started a new game, then that is an incompatibility with one of your other scripts and you need to disable them one after another until you find the conflicting script, then try to find a compatibility patch.

I have now gone through and when I disabled them they either crashed almost immediately, or when I reached that same point.
You can see this method in Game_Battler:


def extra_evs(stat)
equips.inject(0) {|r, equip| r += equip.extra_evs(stat)}
end


It's right at the start in that script you linked.


If an actor got an empty equip slot, you will get that error, because that code above will try to call that extra_evs method on a non-existent equip item (which is actually nil).


To fix it, just replace that method with this one:


def extra_evs(stat)
equips.inject(0) {|r, equip| next if equip.nil?; r += equip.extra_evs(stat)}
end


And the error should disappear.
You can see this method in Game_Battler:



def extra_evs(stat)
equips.inject(0) {|r, equip| r += equip.extra_evs(stat)}
end


It's right at the start in that script you linked.


If an actor got an empty equip slot, you will get that error, because that code above will try to call that extra_evs method on a non-existent equip item (which is actually nil).


To fix it, just replace that method with this one:



def extra_evs(stat)
equips.inject(0) {|r, equip| next if equip.nil?; r += equip.extra_evs(stat)}
end


And the error should disappear.

This solved it, Thank you so much.

Original thread: https://forums.rpgmakerweb.com/threads/nomethoderror-in-a-script-i-use.63052/