NoMethod Error Occured. Undefined Method [] for nil:NilClaSS

I have a Yanfly script that affects the battle system, and in battle it works fine, but when I walk around on the map, I get a few steps and then I get the error outlined above, and then it points me here; 
 

#-------------------------------------------------------------------------- # alias method: on_turn_end #-------------------------------------------------------------------------- alias game_battler_on_turn_end_ftb on_turn_end def on_turn_end game_battler_on_turn_end_ftb init_ftb_actions @has_defended = false #grs if self.is_a?(Game_Actor) $game_temp.current_decays[self.id][1] = 0 endend


Here is the entire (altered from its original) script for reference. 

http://pastebin.com/WptB7fuF
The script forum is for presenting scripts you wrote yourself


I've moved this thread to Script Support. Please be sure to post your threads in the correct forum next time. Thank you.


How did you start the game where the error happens? Did you start a new game or did you load an old savefile?


Because in 90% of all cases, "undefined for NIL" happens if you forgot to start a new game after installing a script that needs to have its data initialised by "new game".
The script does not seem to contain the section where the current_decoys property is initialized/made accessible. It's probably part of another script of yours. Make sure it is properly initialized:

In order to make

$game_temp.current_decoys[self.id]...

work, current_decoys must be an Array/Hash or something else that supports []. In order to make

$game_temp.current_decoys[self.id][1]...

work, the entry corresponding to index self.id must be an Array/Hash/... too (uninitialized array entries are considered nil, so if you used an array, make sure it has a suitable length).

Unlike the other $game_... objects, $game_temp is not saved within your savestates, so I'd say it would be unlikely that there is an issue with an old savefile, though it's possible of course.

However, this also means that whatever you store within $game_temp is lost when you quit the game. Also, its current content is carried over when you return to the title and then load a different savestate, so make sure this behaviour does not cause other problems.
As you can tell, I'm very new to scripting. This script has some minor modification made by some friends, but I'm still trying to learn to troubleshoot myself.

The weird thing is, it works if it's

 

Code:
#--------------------------------------------------------------------------  # alias method: on_turn_end  #--------------------------------------------------------------------------  alias game_battler_on_turn_end_ftb on_turn_end  def on_turn_end    game_battler_on_turn_end_ftb    init_ftb_actions    if self.is_a?(Game_Actor)      $game_temp.current_decays[self.id][1] = 0    end  end

 

...but not if it reads after an addition...

 

Code:
 #--------------------------------------------------------------------------  # alias method: on_turn_end  #--------------------------------------------------------------------------  alias game_battler_on_turn_end_ftb on_turn_end  def on_turn_end    game_battler_on_turn_end_ftb    init_ftb_actions    @has_defended = false #grs  if self.is_a?(Game_Actor)  $game_temp.current_decays[self.id][1] = 0end

 

What's the difference that additional modification is making?

Original thread: https://forums.rpgmakerweb.com/threads/nomethod-error-occured-undefined-method-for-nil-nilclass.53358/