SCRIPT ERROR?

Posts

Pages: 1
So I'm creating three extra attributes in RMXP, guard_skill, evasion_skill and deflection_skill. I've got them all built into the status menu just fine . . . except that for some reason, the script will only generate the values for the first three characters that are in the party when the game starts. I've tested it in a blank project and have the same issue. Could someone maybe look at this and tell me what I'm doing wrong? Here's what I've written so far:

class Game_Actor < Game_Battler

attr_accessor :guard_skill
attr_accessor :deflection_skill
attr_accessor :evasion_skill

alias extra_attributes setup

def setup(actor_id)
extra_attributes(actor_id)

for i in 0...$game_party.actors.size
actor = $game_party.actors(i)
actor.guard_skill = (actor.str / 5 + actor.agi / 15)
actor.deflection_skill = actor.dex / 5
actor.evasion_skill = actor.agi / 5
end
end
end

EDIT: on $game_party.actors(i), I do have the i in brackets, but that makes everything go into italics, so I replaced it with parantheses for the post.
for i in 0...$game_party.actors.size

change it to

for i in 0..$game_party.actors.size
(three periods to two)

One of the stupider parts of Ruby.

*edit*
A explanation demo showing why wouldn't hurt either, right?

when you have
for i in 0...10
print "counter is #{i}"
end
It'll go from 0 to 9

Now for
for i in 0..10
print "counter is #{i}"
end
It'll go form 0 to 10
Hmm, oddly enough when I do that, I get

Script 'att' line 14: NoMethodError occurred.
Undefined method 'str' for nil:NilClass

Oddly enough, even when I dump the whole 'def str' method (is that the right term? I'm new to scripting) in there, that error still occurs. Any ideas?
No, that was my mistake. I thought it was a quick issue and made a stupid mistake :\

First off, put everything in code tags. It'll fix the italics issue so you can do this:
array[i] = another_array[i]

without italics!

Next, you shouldn't try to setup every actor in the Game_Actor class. The actors are setup all at once and the way you have it you'll be constantly redoing the calculations when any actor is setup. Each Game_Actor should only be responsible for setting itself up. This is more about good style though than bugs.

Next, I'd suggest doing this a different way. Instead of having guarding ability variables for the class, make them methods. This'll be easier, values are determined on the fly, and (hopefully) bug free! Here's what I'd suggest:


class Game_Actor < Game_Battler
def guard_skill
return (self.str / 5 + self.agi / 15)
end

def deflection_skill
return self.dex / 5
end

def evasion_skill
return self.agi / 5
end

end


Also if you ever do an alias, always add a "unless $@" (without the quotes). This prevents a stupid RGSS bug when you push F12 with certain methods.

I know it isn't exactly fixing the bug, but I can't test anything because RMXP crashes the instant it starts right now and I have no idea why :|
Yay, it works perfectly! Thanks!
Pages: 1