Help with Jet's Skill Self Effects script

Hi there im new around here, this is my first post! I was running through the official tutorials and installed Jet's Skill Self Effects script. Although i havent even tried to implement any features of the script, when i test my project it crashes with an error every time i attack

Error: Script 'skill self effects' line 37: NoMethodError occurred

           Undefined method '[]' for nil:NilClass

Here is the text copied from the script:

#===============================================================================

# Skill Self Effects

# By Jet10985 (Jet)

# Requested by Touchfuzzy

#===============================================================================

# This script will allow you to specify a skill's effects tot arget the user

# instead of the target, on skills that don't already effect the user.

# This script has: 0 customization options.

#===============================================================================

# Overwritten Methods:

# None

#-------------------------------------------------------------------------------

# Aliased methods:

# Game_Battler: item_effect_apply

#===============================================================================

=begin

To specify the effects, use this notetag in the skill's notebox:

 

<self effect: 1>

or

<self effect: 1, 2, 3> to specify more than 1 effect

--------------------------------------------------------------------------------

Use of this script could be as the following.

 

You make a "Berserk Strike" skill, which does 200% damage to an enemy.

You make the 2nd effect "Defense Down 50%" and want it applied to the user.

You'd use this notetag: <self effect: 2>

=end

 

class RPG::Skill

  

  def self_effects

    if @self_effects.nil?

      @self_effects = []

      self.note.each_line {|a|

        scan = a.scan(/<self[ ]*effect[ ]*\:[ ]*(\d+(?:[ ]*,[ ]*\d+)*)>/i)

        scan[0][0].scan(/\d+/).each {|b|                                                         #//////////*************/////////// this is line 37 😀 /////////////************////////#

          @self_effects.push(@effects[b.to_i - 1]) if b.to_i >= 1

        }

      }

    end

    @self_effects

  end

end

 

class Game_Battler

  

  alias jet3745_item_effect_apply item_effect_apply

  def item_effect_apply(user, item, effect, reffed = false)

    if item.is_a?(RPG::Skill) && item.self_effects.include?(effect) && !reffed

      user.item_effect_apply(user, item, effect, true)

      return

    end

    jet3745_item_effect_apply(user, item, effect)

  end

end
Does this fix the issue?

Spoiler
Code:
#===============================================================================# Skill Self Effects# By Jet10985 (Jet)# Requested by Touchfuzzy#===============================================================================# This script will allow you to specify a skill's effects to target the user# instead of the target, on skills that don't already effect the user.# This script has: 0 customization options.#===============================================================================# Overwritten Methods:# None#-------------------------------------------------------------------------------# Aliased methods:# Game_Battler: item_effect_apply#================================================================================beginTo specify the effects, use this notetag in the skill's notebox: <self effect: 1>or<self effect: 1, 2, 3> to specify more than 1 effect--------------------------------------------------------------------------------Use of this script could be as the following. You make a "Berserk Strike" skill, which does 200% damage to an enemy.You make the 2nd effect "Defense Down 50%" and want it applied to the user.You'd use this notetag: <self effect: 2>=end class RPG::Skill    def self_effects    if @self_effects.nil?      @self_effects = []      self.note.each_line {|a|        scan = a.scan(/<self[ ]*effect[ ]*\:[ ]*(\d+(?:[ ]*,[ ]*\d+)*)>/i)        scan[0][0].scan(/\d+/).each {|b|          @self_effects.push(@effects[b.to_i - 1]) if b.to_i >= 1        } unless scan[0].nil?      }    end    @self_effects  endend class Game_Battler    alias jet3745_item_effect_apply item_effect_apply  def item_effect_apply(user, item, effect, reffed = false)    if item.is_a?(RPG::Skill) && item.self_effects.include?(effect) && !reffed      user.item_effect_apply(user, item, effect, true)      return    end    jet3745_item_effect_apply(user, item, effect)  endend
thanks for the fast reply!

afraid that didnt fix the issue, same error as before
Really? I replicated the attack error the first time and replacing the old script with the new one I posted seemed to fix the issue.

If you're using the Database's battle test, make sure you save your project after replacing the old script with the new one or else the new script won't take effect.
How embarrassing! Yep thats fixed it! thanks very much, i know this is maybe asking a lot but could you please explain the error and how you fixed it? I think i understand but it would help!
Well, I only changed line 39 to add a conditional

unless scan[0].nil?
Which checks if the 1st item in "scan" is equal to nil.

Placing a conditional on the end of a block, as denoted by the "}" will prevent that block from executing unless the condition is met.

I suppose when I was originally coding it, I forgot to check if the line didn't contain a <self effect> tag. So in laymen's terms, what I did was add that check.
Ah ok thanks for clarifying, and thanks for the script!
I've moved this thread to RGSSx Script Support. Please be sure to post your threads in the correct forum next time. Thank you.


This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

Original thread: https://forums.rpgmakerweb.com/threads/help-with-jets-skill-self-effects-script.19833/