Here is what I tried with $game_troop.enemies.
class Window_MonsterName < Window_Base
def initialize(troop_id)
super(0, 0, 100, 100)
self.contents = Bitmap.new(width - 32, height - 32)
@troop_id = troop_id
#p $game_troop.enemies[0]
refresh
end
def refresh
self.contents.clear
for e in 0..$data_troops[@troop_id].members.size
id = $game_troop.enemies[e].id
self.contents.draw_text(0, 20 * e, 100, 32, $game_enemies[id].name)
end
end
end
Now to explain my attempts.
id = $game_troop.enemies[e].enemy_id
I stored the enemy's ID number in the local variable id.
I got this error when I tried running the game in a battle.
undefined method "enemy_id" for <#Game_Enemy:
I'm sure you're a little puzzled now. "We saw it listed in the method output we did! It has to work! Grrr...this makes no sense?!" Am I right? Well, since my initial attempt failed I'm going to look at the Game_Enemy class methods to see if there is a method that'll return the enemy's ID and if there isn't one, then I'm boned.
def id
return @enemy_id
end
Hey~ what's this little beauty? Strange...it's returning @enemy_id? Isn't that the method name I tried to use for the enemy ID in the window? Yes it is. Public variables can also be used in a way similar to class methods when you use attr_accessor but that's another lesson for another time. Needless to say, @enemy_id doesn't work like that or else I wouldn't have gotten an error. Lets try using $game_troop.enemies[e].id and see if it works.
class Window_MonsterName < Window_Base
def initialize(troop_id)
super(0, 0, 100, 100)
self.contents = Bitmap.new(width - 32, height - 32)
@troop_id = troop_id
#p $game_troop.enemies[0]
refresh
end
def refresh
self.contents.clear
for e in 0..$data_troops[@troop_id].members.size-1
id = $game_troop.enemies[e].id
self.contents.draw_text(0, 20 * e, 100, 32, $game_enemies[id].name)
end
end
end
There. Now lets try it...error...*mimics a famous comedian* Dont. You. Crash. On. Me. You...BASTARD! Programming takes a LOT of patience. I don't know about the godly scripters like Blizzard, Near Fantastica, and SephirothSpawn but I rarely get things right the first time so yea, programming teaches you a little bit about patience. Anywho, back to our error that we got.
undefined method for nil:NilClass
Okies...something isn't right. Lets output the local variable id and comment our self.contents.draw_text method. Well, the variable outputed the monster's id so we know that's not to blame. I'll try using $data_enemies instead. When a $game_variable fails, the $data_variable usually works.
class Window_MonsterName < Window_Base
def initialize(troop_id)
super(0, 0, 100, 100)
self.contents = Bitmap.new(width - 32, height - 32)
@troop_id = troop_id
refresh
end
def refresh
self.contents.clear
for e in 0..$data_troops[@troop_id].members.size-1
id = $game_troop.enemies[e].id
self.contents.draw_text(0, 20 * e, 100, 32, $data_enemies[id].name)
end
end
end
It worked! YEY!
Perseverance(sp?) and patience pays off.