I'm new to scripting and I need a bit of help...

I'm trying to give each class a default attacks and using this:

class Game_BattlerBase


  def attack_skill_id
    if @class_id == 2 
      return 3 
    end
   end
end



This seems simple enough, and yet... It's not working? I'm still getting the normal attack (1).


Maybe I'm placing the script in the wrong place? It's on a event on autorun.
Maybe I'm placing the script in the wrong place? It's on a event on autorun.

That


The script command in the events is a sandbox - everything in it is deleted after processing, no matter how often you start it.


Any engine modifying script needs to be installed in the script editor, it cannot work in the event script command


I suggest you follow the link "how to use a script" in my signature to learn how to use the script editor for existing scripts before heading over to the learning ruby forum for details on writing your own scripts
Ah, thanks, but now it seems to be interfering with some other script saying "no implicit conversion from nil to integer":

 #--------------------------------------------------------------------------
  # * Normal Attack Determination
  #--------------------------------------------------------------------------
  def attack?
    item == $data_skills[subject.attack_skill_id]
  end



I'm kinda weary of touching it, but would turning this code into a quote deal with the problem
You made a condition for a method which MUST return a value, but the condition will NOT be satisfied always (ex, when the actor is not class 3), and when it is not, nothing is returned.


You need to add an 'else' part for your 'if' statement, and put the return value for when the other conditions do not match there.


class Game_BattlerBase
def attack_skill_id
if @class_id == 2
return 3
else
return 1 # This is returned when the actor is not class 3.
end
end
end


Like the above code shows.


Note that regardless if the skill you set for normal attack needs target selection or not, you will still need to select a target for your "Attack" command, even if the skill is a healing spell which targets allies, you will be thrown to select enemies instead of actors.
YES! Thank you!


By the way, I have a book on coding Ruby from a Humble Bundle... that's what the script's use here, right? If so, I'm assuming it's going to incredibly helpful for me.
The engine uses RGSS3 which uses Ruby, yes. I forgot which version of Ruby it uses, but I know that it is not the most recent version.


You can open the script editor and press F1 to bring up the help files for scripting. There are a hell of a lot useful information there about the structure of the RPG database classes and about the properties and methods of most commonly used classes.


And yes, that Ruby book will surely help you to find out about some more advanced methods which aren't detailed in the help files of RPG Maker. Just note that many things are not usable in RGSS3 from Ruby (like gems and rails, and other advanced stuffs), at least not without some extra scripts and files added into the RPG Maker engine.

Original thread: https://forums.rpgmakerweb.com/threads/im-new-to-scripting-and-i-need-a-bit-of-help.56614/