TheShinyMew
Wild Challenger appeared!
- 125
- Posts
- 14
- Years
- she/her
- Unavailable
- Seen Oct 10, 2023
I made a move called Lucky Star, which revives any Pokemon in a party without the user fainting. Here are the code of it in PokeBattle_MoveEffects:
And in PokeBattle_Battle:
But when I used Lucky Star on a fainted Pokemon, I got a powerful error like this:
What's wrong with this?
Code:
class PokeBattle_Move_171 < PokeBattle_Move
def pbEffect(attacker,opponent,hitnum=0,alltargets=nil,showanimation=true)
if attacker.effects[PBEffects::LuckyStar]
@battle.pbDisplay(_INTL("But it failed!"))
return -1
end
pbShowAnimation(@id,attacker,nil,hitnum,alltargets,showanimation)
attacker.effects[PBEffects::LuckyStar]=true
@battle.pbDisplay(_INTL("A lucky star had summoned somewhere."))
return 0
end
end
And in PokeBattle_Battle:
Code:
def pbCanSwitchLax?(idxPokemon,pkmnidxTo,showMessages)
if pkmnidxTo>=0
party=pbParty(idxPokemon)
if pkmnidxTo>=party.length
return false
end
if !party[pkmnidxTo]
return false
end
if party[pkmnidxTo].isEgg?
pbDisplayPaused(_INTL("An Egg can't battle!")) if showMessages
return false
end
if !pbIsOwner?(idxPokemon,pkmnidxTo)
owner=pbPartyGetOwner(idxPokemon,pkmnidxTo)
pbDisplayPaused(_INTL("You can't switch {1}'s Pokémon with one of yours!",owner.name)) if showMessages
return false
end
if party[pkmnidxTo].hp<=0
if isConst?(party[pkmnidxTo].species,PBSpecies,:GENESUNE) ||
isConst?(party[pkmnidxTo].species,PBSpecies,:PERFEON) ||
isConst?(party[pkmnidxTo].ability,PBAbilities,:REBIRTH)
party[pkmnidxTo].healHP
party[pkmnidxTo].healStatus
party[pkmnidxTo].healPP
pbDisplayPaused(_INTL("{1} is revived by its power!",party[pkmnidxTo].name))
return true
thatpokemon=party[pkmnidxTo]
effects=nil
elsif thatpokemon.effects[PBEffects::LuckyStar]=true
thatpokemon.healHP
thatpokemon.healStatus
thatpokemon.healPP
pbDisplayPaused(_INTL("{1} came back to life!",party[pkmnidxTo].name))
thatpokemon.effects[PBEffects::LuckyStar]=false
return true
else
pbDisplayPaused(_INTL("{1} has no energy left to battle!",party[pkmnidxTo].name)) if showMessages
return false
end
end
if @battlers[idxPokemon].pokemonIndex==pkmnidxTo ||
@battlers[idxPokemon].pbPartner.pokemonIndex==pkmnidxTo
pbDisplayPaused(_INTL("{1} is already in battle!",party[pkmnidxTo].name)) if showMessages
return false
end
end
return true
end
But when I used Lucky Star on a fainted Pokemon, I got a powerful error like this:
Code:
Exception: NoMethodError
Message: undefined method `effects' for nil:NilClass
PokeBattle_Battle:1350:in `pbCanSwitchLax?'
PokeBattle_Battle:1374:in `pbCanSwitch?'
PokeBattle_OtherScenes:2682:in `pbSwitch'
PokeBattle_OtherScenes:2664:in `loop'
PokeBattle_OtherScenes:2691:in `pbSwitch'
PokeBattle_Battle:1614:in `pbSwitchPlayer'
PokeBattle_Battle:2930:in `pbCommandPhase'
PokeBattle_Battle:2879:in `loop'
PokeBattle_Battle:2969:in `pbCommandPhase'
PokeBattle_Battle:2868:in `each'
What's wrong with this?