Retrieving data from arrays are faster than retrieving data from hashes.
In this case the difference will probably be so little and finding out whether a given key is present is on average faster than with an array. That is, if you have used the proper methods.
Don't use:
if ps::Passive_Skills.keys.include?(@skills[i])
This will create an array containing the keys in the hash. On this array you check if the skill is present.
Instead you should use:
if ps::Passive_Skills.has_key?(@skills[i]) # Or whatever the correct syntax is.
Change accordingly if there are other places where you use .keys.include?(
something).
I doubt the decrease in speed will be noticeable. Especially if the information is only updated when necessary. The only time that will be is the first time base_maxhp, base_maxsp, base_str and so on. The first time one of them are called after the actor learns or forgets a skill. Basically, whenever the actors skills changes.
You update the passive skills effects whenever base_maxhp is called and only when base_maxhp is called. (Also, why do you update the skills after you add @passive_skills. This could give you the wrong hp bonus one time.)
You rely on base_maxhp being called before the other methods are called. You shouldn't.
One can notice that either
learn_skill or
forget_skill must be called for the skills to change.
I suggest that alias both and let them call the alias as well as setting a flag telling the skills might have been changed; for example
@passive_skills_update = true.
Then we could for example have a base_maxhp method looking like this:
def base_maxhp
ps = Passive_Skills
if @passive_skills_update || @passive_skills_update.nil?
passive_bonus
@passive_skills_update = false
end
n = leon_passiveskills_gameactor_basehp
n = n + (n * @passive_hp * 0.01)
return n
end
And have similar changes to the other base methods.
Note the code I have written here has not been tested. So don't be surprised if you encounter errors, be critical
You have made accessor for the passive_hp, passive... and so on (attr_accessor :passive_hp)
Why have you made them as accessors and not as readers? (attr_reader :passive_hp)
Changes to the passive values will just be overwritten next time a passive skill is learned or forgotten.
I suggest you test how it works with old saves
All this time I have focused on the problems. I hope you did not get discourage. I wanted to help you make the script better.
It is a nice script as modern said. There were just some inefficiencies in it. Another question is what did you do right. What was good?
It would be unfortunate if you removed or changed a good feature into something worse during the effort of making it even better.
I like how you showed which parts was added to the Window_Skill so it should be relatively easy for the users to add the changes themselves
I like the idea. Good job coming up with it
The way you aliased the base_ methods in Game_Actor. Should increase compatibility with other scripts.
I'll look forward to your revision.
*hugs*
- Zeriab