Changing a script variable in game

nio kasgami

VampCat
Veteran
Joined
May 21, 2013
Messages
8,949
Reaction score
3,042
First Language
French
Primarily Uses
RMMV
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)
 

Evgenij

Veteran
Veteran
Joined
Aug 28, 2013
Messages
349
Reaction score
100
First Language
German
Primarily Uses
N/A
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.
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,098
Reaction score
13,704
First Language
English
Primarily Uses
RMMV
$game_variables[x] = y


Don't put leading zeros on the x. Instead of $game_variables[001], just write $game_variables[1].
 
Last edited by a moderator:

Zalerinian

Jack of all Errors
Veteran
Joined
Dec 17, 2012
Messages
4,696
Reaction score
935
First Language
English
Primarily Uses
N/A
$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.
 

nio kasgami

VampCat
Veteran
Joined
May 21, 2013
Messages
8,949
Reaction score
3,042
First Language
French
Primarily Uses
RMMV
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~

$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

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
 
Last edited by a moderator:

Evgenij

Veteran
Veteran
Joined
Aug 28, 2013
Messages
349
Reaction score
100
First Language
German
Primarily Uses
N/A
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.
 

nio kasgami

VampCat
Veteran
Joined
May 21, 2013
Messages
8,949
Reaction score
3,042
First Language
French
Primarily Uses
RMMV
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 ~
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,098
Reaction score
13,704
First Language
English
Primarily Uses
RMMV
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.
 

Mithran

Global Moderators
Global Mod
Joined
Mar 2, 2012
Messages
404
Reaction score
217
First Language
English
Primarily Uses
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.
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

Couple hours of work. Might use in my game as a secret find or something. Not sure. Fancy though no? :D
Holy stink, where have I been? Well, I started my temporary job this week. So less time to spend on game design... :(
Cartoonier cloud cover that better fits the art style, as well as (slightly) improved blending/fading... fading clouds when there are larger patterns is still somewhat abrupt for some reason.
Do you Find Tilesetting or Looking for Tilesets/Plugins more fun? Personally I like making my tileset for my Game (Cretaceous Park TM) xD
How many parameters is 'too many'??

Forum statistics

Threads
105,862
Messages
1,017,047
Members
137,569
Latest member
Shtelsky
Top