Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

HBGames

Code:
#==============================================================================
# ** Game_Weapon
#------------------------------------------------------------------------------
#  This script controls the gun operations.
#==============================================================================

class Game_Weapon
  def initialize
    @bullet = []
    for i in 0..29
      @bullet[i[2]] = 0
    end
    @bulletspeed = 1
    for i in 0..29
      @sprite_bullet = [i]
    end
  end

  def movebullet
    for i in 0..29
      if @bullet[i[2]] == 1
        @sprite_bullet[i].x += @bullet[i[0]]
        @sprite_bullet[i].y += @bullet[i[1]]
      end
    end
  end
  
  def trigger
    if Mouse.click?(1)
      for i in 0..29
        if @bullet[i[2]] == 0
          @angle = Math.atan((Mouse.pixels[0]-320)/((Mouse.pixels[1]-240)*-1))
          @bullet[i[0]] = @bulletspeed / (Math.sin @angle)
          @bullet[i[1]] = @bulletspeed / (Math.cos @angle)
          @sprite_bullet[i] = Sprite.new
          @sprite_bullet[i].bitmap = RPG::Cache.picture("bullet.PNG")
          @sprite_bullet[i].x = 320
          @sprite_bullet[i].y = 240
          @bullet[i[2]] = 1
          break
        end
      end
    end
  end
  
  def update
    for i in 0..29
      if @bullet[i[2]] == 1
        @sprite_bullet[i].update
      end
    end
  end
  
end

I keep getting an undefined method error

Code:
Script 'Game_Weapon' line 22: NoMethodError occurred
undefined method 'x' for nil:NilClass

Which is refering to this line (and probably the other lines using .x and .y)

@sprite_bullet.x += @bullet[i[0]]

I'm using DerVVulfmans Revised Mouse Script.

Anyone have any an anwser to my problem?

-Charles-

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top