Hello. I seem to have done something wrong when writing these scripts.
I'm getting a NoMethodError, undifined method `[]' for Nil:nilClass on line 3 for this little test when using the above scripts.
If somebody could help me, I'd be grateful.
Thankee.
Peace Out!
~Broken
Code:
class Game_NPCs < NPC_Database
NPC_COUNT = 2
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize
@data = []
end
#--------------------------------------------------------------------------
# * Get NPC
# npc_id : npc ID
#--------------------------------------------------------------------------
def [](npc_id)
if npc_id > NPC_COUNT or @npcs[npc_id] == nil
return nil
end
if @data[npc_id] == nil
@data[npc_id] = Game_NPC.new(npc_id)
end
return @data[npc_id]
end
end
Code:
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
#MARRIAGE_MIN = 18 #The youngest age an NPC can be to get married
def initialize(npc_id)
super()
setup(npc_id)
end
def setup(npc_id)
@npc_id = npc_id
@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
def id
return @npc_id
end
end
I'm getting a NoMethodError, undifined method `[]' for Nil:nilClass on line 3 for this little test when using the above scripts.
Code:
class Scene_NPCTest
def initialize
@e = $game_npc[1].id
end
def main
print @e
print $game_npc[0].id
$scene = Scene_Map.new
end
end
If somebody could help me, I'd be grateful.
Thankee.
Peace Out!
~Broken