Calling Methods and Mixing Scripts

Hi there.

I wasn't sure whether to post this in Learning Ruby and RGSSx, or RGSSx Script Support, so I apologise in advance if this is in the wrong place.

Here's a bit of background on the scripts I'm having trouble with:

Spoiler
I've been working on this VX project for a long time - it uses an old action battle system called Requiem SBABS 4 by Vlad.

Part of the ABS allows you to bind spells to hotkeys from the skill menu. I combined this with the YEM Skill Overhaul script by Yanfly to make character progression involve unlocking a spell from one school of magic, and then upgrading that one spell to become more powerful.

Surprisingly, these scripts worked well together, except for one fact - you had to manually re-bind each spell whenever you purchased an upgrade (the old spell would remain bound to the key and usable despite not being in the skill window).

I decided I'd have a go at creating a system to automatically re-bind the spells when upgrades were purchased. I disabled the ability to manually choose which spell to be on each key in favour of making a simple rule of Fire on [1], Ice on [2], and Thunder on [3].

As it stands, my automatic re-binding script edit works perfectly. The one problem I have now is that I need to bind the spells to the hotkeys when they are first learned. I'd hoped this would be as simple as calling my custom script from an event when the spell is learned, but I'm getting NoMethodErrors and the like.

This is the relevant code from YEM Skill Overhaul - I've omitted most of the unrelated code

Spoiler
class Scene_Skill < Scene_Base def update_learn_selection @learn_window.update @learn_data.update if Input.trigger?(Input:: Sound.play_cancel @command_window.active = true @learn_window.active = false @skill_window.refresh if @skill_window != nil @passive_window.refresh if @passive_window != nil# *** omitted some unrelated code from here *** elsif Input.trigger?(Input::C) skill = @learn_window.skill if @learn_window.enabled?(skill) and [email protected]_learn?(skill) learn_skill(skill) autobind = skill.id # <---------------------- Set up the skill ID for autobinding autobind_skill(autobind) # <-------------- Call the autobinding function else Sound.play_buzzer end end endend
Next is the custom script which I've been working on to allow the automatic re-binding. It is written in the Requiem script.

This part of the code works just fine:

Spoiler
class Scene_Skill < Scene_Base attr_accessor :message attr_accessor :delay # *** omitted a couple of unrelated methods here *** def autobind_skill(autobind) # FIRE SKILLS if autobind >= 59 and autobind <= 64 autobind_button = 1 end # ICE SKILLS if autobind >= 65 and autobind <=70 autobind_button = 2 end # THUNDER SKILLS if autobind >= 71 and autobind <= 76 autobind_button = 3 end # AUTOBIND if autobind_button == 1 @actor.skill_hotkeys[49] = autobind end if autobind_button == 2 @actor.skill_hotkeys[50] = autobind end if autobind_button == 3 @actor.skill_hotkeys[51] = autobind end endend
This is where I get stuck. I need a "Script..." method to call from an event when the player learns the new skills.

This is the code which I've been working on, but nothing I've done has worked:

Spoiler
class Scene_Skill #AUTO ADD def autoadd_fire @actor.skill_hotkeys[49] = 59 end def autoadd_ice @actor.skill_hotkeys[50] = 65 end def autoadd_thunder @actor.skill_hotkeys[51] = 71 endend
I'm not sure if it's a problem with my code, or a problem with my script call, or what.

I've tried many different approaches, such as making it a Module (which, if I recall correctly resulted in the @actor stuff not working), as its own new class or as part of Scene_Skill (both of which, I think, ended with NoMethodErrors).

If someone would be able to help me figure this out I'd be really, really thankful.

Knowing my luck, it's probably something really simple and obvious and my somewhat limited knowledge of Ruby has just continually led me in circles for the past 4 hours...

Oh well.

Thanks in advance to anyone who's able to shed some light on this.

edit:

I've put together a small demo for anyone who's willing to take a look at it

Download here: http://www.mediafire.com/download/nq0voxxqnpukdvo/AutobindDemo.zip

Thanks again for any help.
Did you try refreshing the hot keys after your auto-bind. That should work. If not, there might be a little more code needed.
Thanks for the reply.

As I said, the problem isn't with the auto-bind. That works fine.

It's when I try to do an event script call to manually bind a spell...

For instance, player reaches level 2 and learns Fire. Because that was learnt through an event rather than the Skill Window where upgrades take place, it isn't automatically bound.. so I have an event with a [script...] "Scene_Skill.autoadd_fire" which should manually bind skill with ID 59 (Fire) to hotkey 49 (keyboard button [1]) .. but instead that crashes the game with a NoMethodError (undefined method `autoadd_fire' for Scene_Skill:Class).
Yeah, since it's a particular script you're having trouble with, it goes into Script Support and not Learning ...


I'll move it
Yeah, since it's a particular script you're having trouble with, it goes into Script Support and not Learning ...

I'll move it
Thanks, I wasn't sure because I'm making my own bits of code to get them to work together properly.

I've also updated the original post with a download link for a demo, in case anybody wants to take a look at the scripts.

Thanks again.

edit: I don't really need help with this any more. I've made a work-around using dummy skills. I'd still be interested in knowing how this would have worked, if anyone figures it out, but it's not really necessary now. Thanks anyway.

Original thread: https://forums.rpgmakerweb.com/threads/calling-methods-and-mixing-scripts.21194/