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.

[Resolved] Fixnum Error

Status
Not open for further replies.

OS

Sponsor

I am trying to setup some data using a for loop, but I keep getting this error:

Script 'Game_NPC' line 80: NoMetodError occurred.

undefined method `each' for 2:Fixnum

Here is the script:
Code:
class Scene_Title
  def command_new_game
    # Play decision SE
    $game_system.se_play($data_system.decision_se)
    # Stop BGM
    Audio.bgm_stop
    # Reset frame count for measuring play time
    Graphics.frame_count = 0
    # Make each type of game object
    $game_temp          = Game_Temp.new
    $game_system        = Game_System.new
    $game_switches      = Game_Switches.new
    $game_variables     = Game_Variables.new
    $game_self_switches = Game_SelfSwitches.new
    $game_screen        = Game_Screen.new
    $game_actors        = Game_Actors.new
    $game_party         = Game_Party.new
    $game_troop         = Game_Troop.new
    $game_map           = Game_Map.new
    $game_player        = Game_Player.new
    $game_npc           = Game_NPC.new   #NEW LINE HERE*************************
    # Set up initial party
    $game_party.setup_starting_members
    # Set up initial map position
    $game_map.setup($data_system.start_map_id)
    # Move player to initial position
    $game_player.moveto($data_system.start_x, $data_system.start_y)
    # Refresh player
    $game_player.refresh
    # Run automatic change for BGM and BGS set with map
    $game_map.autoplay
    # Update map (run parallel process event)
    $game_map.update
    # Switch to map screen
    $scene = Scene_Map.new
  end
end

class NPC_Database
  #NPC_COUNT = 2
  def initialize
   #item# = [five item ids]
    item1 = [1, 1, 1, 2, 3]
   #clothes# = [shield, helmit, body_armour, accessory]
    clothes1 = [1, 10, 22, 32]
   #var = [0last_name, 1middle_name, 2first_name, 3age, 4sex, 5marriage, 6disp, 7bounty, 8lvl, 9items, 10clothes, 11weapon]
    n1 = ["Testons", "Testing", "Testy", 14, 1, [false, ], 50, 0, 16, item1, clothes1, 1]
    n2 = ["Killer", "The", "Im", 17, 0, 0, 1000, 23, [1, 1, 1, 2, 3], [1, 10, 22, 32], 1]
    @npcs = [n1, n2]
  end
end

class Game_NPC < NPC_Database
  attr_accessor :id
  attr_accessor :surname
  attr_accessor :middle
  attr_accessor :name
  attr_accessor :age #Used in same-sex marriages (Checked for oldest)
  attr_accessor :sex #gender
  attr_accessor :marriage
  attr_accessor :disp #Explained later
  attr_accessor :bounty #Explained later
  attr_accessor :lvl #used in same-sex marriages and battles (Checked for highest)
  attr_accessor :hp #used in battle
  attr_accessor :items #an array that holds up to 5 items.
  attr_accessor :clothes #an array that holds Body, Head, Hand, Feet, and Shield Equiped armour.
  attr_accessor :weapon #a variable that holds 1 weapon
 #attr_accessor :skills #an array holding any (5) skills/spells the NPC knows
 #attr_accessor :mp
 NPC_COUNT = 2
 MARRIAGE_MIN = 18 #The youngest age an NPC can be to get married
 def initialize
   super()
   $data_npc = []
   setup(NPC_COUNT)
 end
 
 def setup(npc_count)
   for i in 2 #npc_count
     $data_npcs << @npcs[i]
     npc = $data_npcs[i]
     @npc_id = i
     @surname = npc[i][0]
     @middle = npc[i][1]
     @name = npc[i][2]
     @age = npc[i][3]
     @sex = npc[i][4]
     @disp = npc[i][5]
     @bounty = npc[i][6]
     @lvl = npc[i][7]
     @hp = 100 #Percentages only
     @items = npc[i][8]
     @clothes = npc[i][9]
     @weapon = npc[i][10]
   end
 end
 
 def id
   return @npc_id
 end
end

Can someone help me? I really appreciate it if someone can. Peace out!
~Broken
 
your for sintax is wrong.
for i in 2 will take "i" as each element of the array. and 2 is not an array.
use for i in 0..2 instead (by this way "i" will be 0, then 1, then 2.).
 

OS

Sponsor

Yeah, I just realised my mistake when looking at AstroMech's tut. I forgot that I was supposed to use an array or range, becuase Fixnum/Numeral doesn't have the method each. I am about to fix that now. Thanks!

Peace out!

~Broken

P.S. RESOLVED
 
Status
Not open for further replies.

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