• Just a reminder that providing specifics on, sharing links to, or naming websites where ROMs can be accessed is against the rules. If your post has any of this information it will be removed.
  • Ever thought it'd be cool to have your art, writing, or challenge runs featured on PokéCommunity? Click here for info - we'd love to spotlight your work!
  • Welcome to PokéCommunity! Register now and join one of the best fan communities on the 'net to talk Pokémon and more! We are not affiliated with The Pokémon Company or Nintendo.

[Scripting Question] How to set Variable to one after using move

  • 10
    Posts
    3
    Years
    • Seen Jun 13, 2022
    I know pretty much nothing about coding but I want to create a move function where a custom move adds 1 to a variable when you use it. It seems simple so I imagine it's not hard but again, I don't know squat about coding and instead of watching an hour long YouTube video I'm just going to ask you guys. You can just call the variable 'test' for this example.
    Edit: I figured out how to use add variables but for some reason it isn't sticking after battle. Here's the code I used:

    class PokeBattle_Move_200 < PokeBattle_Move
    def pbEffectAfterAllHits(user,target)
    return if !target.damageState.fainted
    return if !user.pbCanRaiseStatStage?(:ATTACK,user,self)
    $game_variables[0026] += 1
    end
    end

    For a base I used fell stinger
     
    Last edited:
    Haha, it actually is sticking around, but not quite where you think it is!

    You see, when you put leading zeros in front of a number in ruby, ruby treats it as an octal, a base 7 number. So instead of adding one to variable 26, you were actually adding 1 to variable 22.
    You can check it in the debug menu to see for yourself :)

    Of course, the fix is simple, just 26, no zeros, is good enough. Glad to see you figured out how to add to a game variable by yourself though, learn some knowledge by searching for that information :)
     
    Back
    Top