Scripting New Move

updawg734

Whats up, dawg?
Member
Joined
Apr 26, 2017
Posts
89
I am working on implementing a new move that I have created, and have been running into some errors with the scripting of the effect. Wondering if anyone with more knowledge of scripting/code can help identify my errors?

Basically, the move functions the same as Absorb (deals damage, heals user up to 50% of damage dealt). However, if your opponent is Lotad, Lombre, or Ludicolo, the move will be a OHKO. To get the basis for the move effect code, I copied parts from the OHKO effect (guillotine, fissure, etc.) and also parts from Absorb's effect for the "else" bit.

I keep getting errors when trying to play test the game. Some syntax errors, and also a problem with the definition of "opponent" that I can't seem to figure out.

Here is what my code looks like so far in PokeBattle_MoveEffects:

Code:
class PokeBattle_Move_161 < PokeBattle_Move
 if isConst?(opponent.species,PBSpecies,:LOTAD,:LOMBRE,:LUDICOLO) 
  def pbEffect(attacker,opponent,hitnum=0,alltargets=nil,showanimation=true)
    damage=pbEffectFixedDamage(opponent.totalhp,attacker,opponent,hitnum,alltargets,showanimation)
    if opponent.fainted?
      @battle.pbDisplay(_INTL("It's a one-hit KO!"))
    end
    return damage
  end
  else
    def isHealingMove?
      return USENEWBATTLEMECHANICS
    end

    def pbEffect(attacker,opponent,hitnum=0,alltargets=nil,showanimation=true)
      ret=super(attacker,opponent,hitnum,alltargets,showanimation)
      if opponent.damagestate.calcdamage>0
        hpgain=(opponent.damagestate.hplost/2).round
        if opponent.hasWorkingAbility(:LIQUIDOOZE)
          attacker.pbReduceHP(hpgain,true)
          @battle.pbDisplay(_INTL("{1} sucked up the liquid ooze!",attacker.pbThis))
        elsif attacker.effects[PBEffects::HealBlock]==0
          hpgain=(hpgain*1.3).floor if attacker.hasWorkingItem(:BIGROOT)
          attacker.pbRecoverHP(hpgain,true)
          @battle.pbDisplay(_INTL("{1} had its energy drained!",opponent.pbThis))
        end
      end
      return ret
    end
  end
end

Any help is greatly appreciated!!
 

NettoHikari

Trainer
Member
Joined
Jan 4, 2019
Posts
97
I keep getting errors when trying to play test the game. Some syntax errors, and also a problem with the definition of "opponent" that I can't seem to figure out.
As soon as you find yourself saying "I keep getting errors", follow it up with the ACTUAL ERROR. That tells us more information than anything (apart from your code itself).

That said, the issue in your case is that you tried putting function declarations inside of conditionals. Basically, any time you find yourself putting "def" statements inside of "if" statements (or anything that isn't "class" or "module"), you're probably doing something wrong. You need to rearrange your code like so:

Ruby:
class PokeBattle_Move_161 < PokeBattle_Move
  def isHealingMove?
    return USENEWBATTLEMECHANICS
  end

  def pbEffect(attacker,opponent,hitnum=0,alltargets=nil,showanimation=true)
    ret=super(attacker,opponent,hitnum,alltargets,showanimation)
    if isConst?(opponent.species,PBSpecies,:LOTAD) ||
       isConst?(opponent.species,PBSpecies,:LOMBRE) ||
       isConst?(opponent.species,PBSpecies,:LUDICOLO)
      damage=pbEffectFixedDamage(opponent.totalhp,attacker,opponent,hitnum,alltargets,showanimation)
      if opponent.fainted?
        @battle.pbDisplay(_INTL("It's a one-hit KO!"))
      end
      ret = damage
    end
    if opponent.damagestate.calcdamage>0
      hpgain=(opponent.damagestate.hplost/2).round
      if opponent.hasWorkingAbility(:LIQUIDOOZE)
        attacker.pbReduceHP(hpgain,true)
        @battle.pbDisplay(_INTL("{1} sucked up the liquid ooze!",attacker.pbThis))
      elsif attacker.effects[PBEffects::HealBlock]==0
        hpgain=(hpgain*1.3).floor if attacker.hasWorkingItem(:BIGROOT)
        attacker.pbRecoverHP(hpgain,true)
        @battle.pbDisplay(_INTL("{1} had its energy drained!",opponent.pbThis))
      end
    end
    return ret
  end
end

In general, if you want to fix syntax errors on your own, you should try to learn how the syntax works in the first place. I'd recommend reading Marin's tutorial on Ruby: https://reliccastle.com/ruby/
 
Last edited by a moderator:

updawg734

Whats up, dawg?
Member
Joined
Apr 26, 2017
Posts
89
As soon as you find yourself saying "I keep getting errors", follow it up with the ACTUAL ERROR. That tells us more information than anything (apart from your code itself).

That said, the issue in your case is that you tried putting function declarations inside of conditionals. Basically, any time you find yourself putting "def" statements inside of "if" statements (or anything that isn't "class" or "module"), you're probably doing something wrong. You need to rearrange your code like so:

Ruby:
class PokeBattle_Move_161 < PokeBattle_Move
  def isHealingMove?
    return USENEWBATTLEMECHANICS
  end

  def pbEffect(attacker,opponent,hitnum=0,alltargets=nil,showanimation=true)
    ret=super(attacker,opponent,hitnum,alltargets,showanimation)
    if isConst?(opponent.species,PBSpecies,:LOTAD) ||
       isConst?(opponent.species,PBSpecies,:LOMBRE) ||
       isConst?(opponent.species,PBSpecies,:LUDICOLO)
      damage=pbEffectFixedDamage(opponent.totalhp,attacker,opponent,hitnum,alltargets,showanimation)
      if opponent.fainted?
        @battle.pbDisplay(_INTL("It's a one-hit KO!"))
      end
      ret = damage
    end
    if opponent.damagestate.calcdamage>0
      hpgain=(opponent.damagestate.hplost/2).round
      if opponent.hasWorkingAbility(:LIQUIDOOZE)
        attacker.pbReduceHP(hpgain,true)
        @battle.pbDisplay(_INTL("{1} sucked up the liquid ooze!",attacker.pbThis))
      elsif attacker.effects[PBEffects::HealBlock]==0
        hpgain=(hpgain*1.3).floor if attacker.hasWorkingItem(:BIGROOT)
        attacker.pbRecoverHP(hpgain,true)
        @battle.pbDisplay(_INTL("{1} had its energy drained!",opponent.pbThis))
      end
    end
    return ret
  end
end

In general, if you want to fix syntax errors on your own, you should try to learn how the syntax works in the first place. I'd recommend reading Marin's tutorial on Ruby: https://reliccastle.com/ruby/

Thank you so much for your help, it works perfectly now!

I understand that it is best practice to post the exact error message. However, in this situation, I didn't think it was necessary because I was mostly getting a bunch of syntax errors. I knew the error had to be in the order/definitions of the code, so I just thought it would be more helpful to see the actual code I was using.

I realize that this is my own fault for not knowing more about Ruby and/or scripting in general, but then again, that was why I sought out help. I appreciate the resource link and will definitely check it out! Thanks again.
 
Top