Changing a script variable in game

● ARCHIVED · READ-ONLY
Started by nio kasgami 9 posts View original ↗
  1. Hello there !

    I do a script for someone I almost finish it but sadly  I block on how to call it in game (via script call)

    I just don't remember how to change a variable in game

    I use the module Sound

    with a  single local

    module Sounddef self something@bss = 0case @bsswhen 0 do somthingwhen 1 do somethingendend

    

    

    

    I am gratefull if you can help me a little I don't want to have script construction or anything I just want to know how to change my variable in game

    ( I was not sure wich treadh this topic go so I put here because I don't need to build a script just to have a information about the variable change)
  2. What do you mean with change a Variable Ingame?

    Do you want to change your @bss Variable through a scriptcall?

    And your function makes no sense, you set the variable to zero and than you make a case with it, the case will always jump to the zero case.
  3. $game_variables[x] = y


    Don't put leading zeros on the x. Instead of $game_variables[001], just write $game_variables[1].
  4. Shaz said:
    $game_variables[x] = yDon't put leading zeros on the x. Instead of $game_variables[001], just write $game_variables[1].
    Putting them doesn't have any effect, it will remove the leading zeros automatically.

    To change the variable, I'm assuming @bss, you need to make it visible. This can be a little different with modules. They're not technically classes, so you need to define the methods you want to use to the module.

    This just means you need to use def self.method. instead of just def method . If you'd like to use attr_access or, you need to do

    class << self

    attr_accessor :bss

    end

    This will create two methods for you, bss, which gets the value of @bss, and bss=, which sets the value of @bss.

    Try that, I believe it should work. But I can't really check, as I'm on my phone at the moment.
  5. eugene222 said:
    What do you mean with change a Variable Ingame?

    Do you want to change your @bss Variable through a scriptcall?

    And your function makes no sense, you set the variable to zero and than you make a case with it, the case will always jump to the zero case.
    No it  is normal because I wanted them to jump on the 0 (it is the nill method )

    and it is when you start the battle it is the battlestart SE so before the battle you put the variable you want so it jump at the specific variable~

    Shaz said:
    $game_variables[x] = y

    Don't put leading zeros on the x. Instead of $game_variables[001], just write $game_variables[1].
    hum okai...but  i try and nop is not work

    Zalerinian said:
    Putting them doesn't have any effect, it will remove the leading zeros automatically.

    To change the variable, I'm assuming @bss, you need to make it visible. This can be a little different with modules. They're not technically classes, so you need to define the methods you want to use to the module.

    This just means you need to use def self.method. instead of just def method . If you'd like to use attr_access or, you need to do

    class << self

    attr_accessor :bss

    end

    This will create two methods for you, bss, which gets the value of @bss, and bss=, which sets the value of @bss.

    Try that, I believe it should work. But I can't really check, as I'm on my phone at the moment.



    well for the moment is not work is not make any bogue but when I start the event before the battle the sound don't play (because in origin it was at 0 (the return nil who make the script disable~)

    sigh...I guess is me who done a error somewhere but I will show you what I do but i am less with self class because I never use them

    THe script inself because .lol this not require a lot of stuff for doing this~

    Code:
    class << self    attr_accessor :bss     def self.bss     @bss = 0  end    endmodule Sound        def self.play_battle_start    case @bss    when 0       return nil    when 1      play_system_sound(7)      when 2     RPG::SE.new("Autodoor",100,100).play        end  end  end
  6. module Sound   class << self    attr_accessor :bss  end    def self.play_battle_start       case @bss          when 1      play_system_sound(7)    when 2     RPG::SE.new("Autodoor",100,100).play else return nil    end  end endThis should work.

    If you make this scriptcall:

    Sound.bss = 1 it will play "system sound(7)" before battle.

    If you set bss to 2 it will play your custom sound, and on any other value it wont play anything.
  7. Sankyou is work well Now I notice after whe don't consider a part

    If whe don't make this

    def self.refresh

    @bss = nil

    end

    (the variable will always still the same until whe change it~)

    sankyou this topic can be close now ~
  8. Zalerinian said:
    Putting them doesn't have any effect, it will remove the leading zeros automatically.

    Many scripts crash because of leading zeros. Whether this one would or not, it's better to get into the habit of NOT using them.
  9. Just to clear this up: leading zeroes in and of themselves don't make a script crash. Having a leading zero not followed by a letter is just a Ruby literal for octal (010 = 8), with an alternate and slightly clearer notation being 0o10 (thats a zero followed by a lower-case o, followed by the number). A crash will only happen if you get a 9 somewhere in the literal since it doesn't exist in base 8, otherwise, you'll be referencing the wrong number without crashing, which can be even worse.


    For reference, having a leading 0x is the notation for hex (0x10 = 16), 0b is the notation for binary (0b10 = 2), 0d is just plain base 10 integer (0d10 = 10). Using e in the middle of a numeric literal is scientific notation (5.23e3 = 5230), and it can't be combined with the other literals.