What's the snippet for checking if a certain skill is learned

● ARCHIVED · READ-ONLY
Started by RoseofCrimson 10 posts View original ↗
  1. $game_party.actors[@actor].skill_learn?(skillid) or skill_include?

    I'm trying to write a script that checks to see if the first member of the party knows x skill (let's say the first skill in the database).

    I'd also like to know the snippet for $game_actors[1] etc etc.
  2. actor.skill_learn?(skill)
    skill *object*, not ID
  3. example?
  4. $game_actors[1].skill_learn?($data_skills[9])
  5. not working... absolutely frustrating.
  6. @gstv87 Just checking - is that bit of code in RGSS? It looks like RGSS3, though of course I could be wrong.
  7. It's was RGSS the solution was as simple as removing the
    $data_skills[9]
  8. @Kes
    the syntax is what I posted first: actor.skill_learn?(skill)
    actor and skill being both objects, regardless of language or data structure.
  9. From the Game_Actor section in the script editor we can peruse the relevant code:
    Code:
      #--------------------------------------------------------------------------
      # * Learn Skill
      #     skill_id : skill ID
      #--------------------------------------------------------------------------
      def learn_skill(skill_id)
        if skill_id > 0 and not skill_learn?(skill_id)
          @skills.push(skill_id)
          @skills.sort!
        end
      end
      (...)
      #--------------------------------------------------------------------------
      # * Determine if Finished Learning Skill
      #     skill_id : skill ID
      #--------------------------------------------------------------------------
      def skill_learn?(skill_id)
        return @skills.include?(skill_id)
      end

    From this we can determine that skill_id should be a number. For example you can do something like this.
    Code:
    # Let us check if the first party member has learned the skill with id 9 in the database
    $game_party.actors[0].skill_learn?(9)
    
    # If you are using this in a script call you may have to split it up over multiple lines
    actor = $game_party.actors[0]
    if actor.skill_learn?(9)
      p "Do stuff here"
    end
    
    # Remember not to include leading zeroes.
    $game_party.actors[0].skill_learn?(09) # Wrong

    Good luck with your script

    *hugs*
    - Zeriab
  10. I figured it out a few hours prior, but thanks for the in depth explanation, Z'. I'm sure it'll help in similar problems in the future.