Hi everyone, I have some doubts about $data_weapons. I was trying to do a simple script that read the note-tag of the data base and save it in a Hash or something like that. But the problem is that I always end up falling in the same error: I use $data_weapons.each do |weap| to pass through all the weapons, but every time I tried to run the script, it gives me the error message of 'undefined method 'each' for nil:NilClass'. I tried something like this:
class RPG::Weapon < RPG::EquipItem
#--------------------------------------------------------------------------
def value
$data_weapons.each do |weap|
weap.note.split (etc etc).each do |something|
etc
and a lot of others class to acess the $data_weapons, but I always got the same error.
It's a simple question... If anyone could help me \o
Byee
hi there,
You should define weap beforehand because its not a instance variable, like putting this right below the comment:
weap = 0
i would also recommend to copy the $data_weapons array into a temporary array like @my_weapons = $data_weapons
because than you can "work" with that data easier, like shuffling it or whatever
hope this helps!
Hi! If i put this @my_weapons = $data_weapons above and then calls the each method $my_weapons.each do |weap|, I still getting the same error "undefined method 'each' for nil:NilClass" )):
But thanks, anyway!
Where are you putting the code? If you're putting it somewhere where $data_weapons has not yet been defined/created, then yes, it will crash.
If what you have in the first post is exactly the code you've got, then yes, it will crash. $data_weapons is made up of RPG::Weapon items, and is not defined within the item. You can't refer to it there.
Grab some of the scripts that already read note tags and see how they do it.
Oh, yes, I forgot the first item is always nil 🙂
Or he/she can use
$data_weapons.each{|w|w.load_notetags if w}but that's pretty much the same
Ohh, now I see. Thanks guys. I just didn't get how to access the durability (in this example) for each weapon. Since each weapon will do the load_notetags function, wouldn't the variable durability have only the last number read?
Oohhhh, everything makes sense now! Thanks, Adiktuzmiko. 🙂
By the way, how can i get the id of the weapon that a x character it's wielding? I was trying something like this $game_actors[1].weapons, but isn't working ):
Well, characters usually have 5 equips : Weapon, Accessory, Headgear, Bodygear and Helmet.
The data abou them is in $game_actors[x].equips
So, for the weapon would be $game_actor[x].equips[0]
I need declare the game actor class to get these values? Cause here in my class, if I tried to print the $game_actor[0].equips[0] or if I tried to put the value get like this
"id_weapon = $game_actor[0].equips[0]",
appears undefined method '[]' for nil:Nil:Class
Sorry, it's $game_actors, not $game_actor.
It depends on what are you trying to achieve.
I wanted to call this $game_actors every time a battle begins, but didn't figure out yet where to put it. I tried something like that:
class Game_Battler < Game_BattlerBase
alias pheryus_gamebattlerbase_1as3s initialize
def initialize
get_weapon_from_actor
pheryus_gamebattlerbase_1as3s
end
def get_weapon_from_actor
id_weapon = $game_actors[0].equips[0]
msgbox(id_weapon)
end
end
When the game starts, a message shows a error of undefined method 'equips'.
Did you try to change that 0 in $game_actors[0].equips[0]?
$game_actors[0] is always a nil:nilClass
ohhh
Now it's giving "SystemStackError occured. stack level too deep"
I think it's because I'm calling the Game_Battler script. My alias it's wrong? I can pass all my code if necessary
[Edit 2]: Now i did it! Fix the errors. The only problem now it's that when I print the $game_actors[1].weapon[0], what really print is the address of the weapon, and not it's ID. Any idea of how can I convert the address to ID?
Um ... there is a method to remove/change equipment. Why don't you just call that, and it will do everything for you?
Look at Game_Interpreter and see what it does when you use the Change Actor Equipment command. Then call the same method in your script.
Oohh, sure, sure. I'm trying to create my first script by myself, but it's been more harder than I guess hahah I stopped the last error putting a .id in the end of weapon[0]. The only problem now it's that I want to know the weapon that a character is wielding during the Battles, so I'm changing a method in the Game_Battler :
def make_damage_value(user, item)
BattleManager.idheroatual(BattleManager.actor.id)
dano = item.damage.eval(user, self, $game_variables)
array_aux = $dano_armas[$id_weapon.to_s]
for i in 1..array_aux[0].to_i
dano += Random.rand(array_aux[1].to_i) + 1
end
@result.make_damage(dano.to_i, item)
end
What really matters here is the call to the idheroatual method that I created here above:
class << BattleManager
def idheroatual(x)
$id_weapon = $game_actors[x].equips[0].id - 1
end
end
It takes the id of the character that is acting to get the weapon he's wielding. But this isn't really working :\ He was working before I add this x parameter (only geetting the game_actors[1]). I tried change the parameter to BattleManager.actor.index or BattleManager.actor.id.to_i, but didn't succeeded.
Thanks for helping me, guys