• 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!
  • Our weekly protagonist poll is now up! Vote for your favorite Trading Card Game 2 protagonist in the poll by clicking here.
  • 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.

[Question] Can we edit Script Variable through Events ?

Sir William

Chemist
  • 72
    Posts
    4
    Years
    • Seen Apr 14, 2021
    Is there any way to edit a script variable value ? For ex-
     
    Last edited:
    A variable this the symbol "$" is a global variable. You can always refer to it anytime. To modify the variable in an event, just insert a script and give it a new value (e.g. $Rank = 10)

    As a general programming tip, this is generally not recommended to use global variables.
    In RPG Maker specifically, unless you want to store a global variable that contains one instance of a complex class (like $PokemonTemp for example), you should store integers and strings (text) in $game_variables[X] where X is a unused index (you can see unused indices in an Event, with "Control Variables").
     
    It would be great if you can provide tye correct code .

    I see the mistake.
    You must make the difference between "==" and "=".
    The sign "==" refers to a test and reads "is equal to", in the sense: "is $game_variables[26] equal to 10?".
    The sign "=" refers to an affectation, and reads "give the value to", in the sense: "give the value 10 to $game_variables[26]"
    So, first step: in your code, in the "if" lines, it should be "==" instead of "=":
    Code:
        if $game_variables[026] == 10
          @sprites["masterclass"] = IconSprite.new(112,94,@viewport)
          @sprites["masterclass"].setBitmap("Graphics/Pictures/Trainer Card/masterclass")
        elsif $game_variables[026] == 5
          @sprites["hyperclass"] = IconSprite.new(112,94,@viewport)
          @sprites["hyperclass"].setBitmap("Graphics/Pictures/Trainer Card/hyperclass")
        elsif $game_variables[026] == 25
          @sprites["superclass"] = IconSprite.new(112,94,@viewport)
          @sprites["superclass"].setBitmap("Graphics/Pictures/Trainer Card/superclass")
        else       
          @sprites["normalclass"] = IconSprite.new(112,94,@viewport)
          @sprites["normalclass"].setBitmap("Graphics/Pictures/Trainer Card/normalclass")
        end

    But I think this code doesn't do what you want.
    What you want is, the same sprite should come in four different forms, depending on the value stored in $game_variables[26]. So the sprites should not be:
    Code:
    @sprites["masterclass"]
    @sprites["hyperclass"]
    @sprites["superclass"]
    @sprites["normalclass"]
    but rather, all four should have the same name (unless you handle them differently after).

    Also, the sprite is probably loaded everytime you show the trainer card. But what happens if your rank is equal to 11? It's not 10, it's not 5, it's not 25, so it will show normalclass instead of masterclass.
    So in fact if should not be "==" but rather ">=" (greater or equal).
    Code:
        if $game_variables[026] >= 10
          @sprites["masterclass"] = IconSprite.new(112,94,@viewport)
          @sprites["masterclass"].setBitmap("Graphics/Pictures/Trainer Card/masterclass")
        elsif $game_variables[026] >= 5
          @sprites["hyperclass"] = IconSprite.new(112,94,@viewport)
          @sprites["hyperclass"].setBitmap("Graphics/Pictures/Trainer Card/hyperclass")
        elsif $game_variables[026] >= 25
          @sprites["superclass"] = IconSprite.new(112,94,@viewport)
          @sprites["superclass"].setBitmap("Graphics/Pictures/Trainer Card/superclass")
        else       
          @sprites["normalclass"] = IconSprite.new(112,94,@viewport)
          @sprites["normalclass"].setBitmap("Graphics/Pictures/Trainer Card/normalclass")
        end
    If your rank is set to 11, it will be greater than 10, and it will be masterclass.

    But if the rank is set to 26? You will also have masterclass, instead of superclass, so in this code, the order matters. You should first test if the rank is greater than 25, then if the rank is greater than 10, and then if the code is greater than 5:
    Code:
        if $game_variables[026] >= 25
          @sprites["superclass"] = IconSprite.new(112,94,@viewport)
          @sprites["superclass"].setBitmap("Graphics/Pictures/Trainer Card/superclass")
        elsif $game_variables[026] >= 10
          @sprites["masterclass"] = IconSprite.new(112,94,@viewport)
          @sprites["masterclass"].setBitmap("Graphics/Pictures/Trainer Card/masterclass")
        elsif $game_variables[026] >= 5
          @sprites["hyperclass"] = IconSprite.new(112,94,@viewport)
          @sprites["hyperclass"].setBitmap("Graphics/Pictures/Trainer Card/hyperclass")
        else       
          @sprites["normalclass"] = IconSprite.new(112,94,@viewport)
          @sprites["normalclass"].setBitmap("Graphics/Pictures/Trainer Card/normalclass")
        end

    Hope that helps, it's great to see someone try to make scripts!
     
    Back
    Top