Global Switches?

Status
Not open for further replies.

Prescott

argggghhh
Veteran
Joined
Aug 28, 2014
Messages
506
Reaction score
422
First Language
English
Primarily Uses
RMMV
I am working on a game in VX Ace for the first time, when I have used XP in the past.

Need to know if there are global switches in the engine, so that I can apply switches to the entire game regardless of a save file existing. I need to do this for options on the Title Screen (custom one made on the map), so changing things like adding modifiers, cheats, and other settings like game volume. Only thing is that it would have to apply to every saved game.

I guess this also raises the question of if changing a global switch would save it somewhere else, not a save file. Because for it to apply to every save file it would need to be saved somewhere in like, the Data folder, right?

If anyone could help me out with this it would be greatly appreciated :)
 

Hudell

Dog Lord
Veteran
Joined
Oct 2, 2014
Messages
3,545
Reaction score
3,715
First Language
Java's Crypt
Primarily Uses
RMMZ
There's no such thing.

But you can achieve that using scripts. Someone probably wrote a script like that at some point, but I don't know any.
 

_Shadow_

Tech Magician Level:
Moderator
Joined
Mar 2, 2014
Messages
4,078
Reaction score
2,654
First Language
Greek
Primarily Uses
RMMZ
I suppose you can do I/O proccesses from a file to achieve this, but that will obviously require a script.
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,098
Reaction score
13,704
First Language
English
Primarily Uses
RMMV
I've moved this thread to RGSS3 Script Requests. Please be sure to post your threads in the correct forum next time. Thank you.
 

Prescott

argggghhh
Veteran
Joined
Aug 28, 2014
Messages
506
Reaction score
422
First Language
English
Primarily Uses
RMMV
Fair enough, just didn't know if it was script related or engine related so I put it in the engine one xD

That's a little sucky, maybe I'll just resort to having one save file instead.
 

Prescott

argggghhh
Veteran
Joined
Aug 28, 2014
Messages
506
Reaction score
422
First Language
English
Primarily Uses
RMMV
That is very intriguing. My only beef with it is that people could load that game up and it would show as like the settings in the load screen. I'd want it to be hidden so it seems like it's part of the engine. Purely aesthetic, I know. Or writing to an .ini file (or a Ruby file, or updating a script, or something) would be REALLY nice.
 

KanaX

Just being a sleepy
Veteran
Joined
Apr 3, 2013
Messages
1,455
Reaction score
1,297
First Language
Broken English.
Primarily Uses
N/A
Not really... This is a global save. You don't actively open it. You tell it which switches  and variables to track and when to save them. After that, you place a load command. Now your might say where can I put it?
 

I personally have an evented Title menu so I just use a parallel process with a script call: "global_load"
 After the global load I place a conditional: is the X switch on? If so then allow me this extra option.

 
 
Last edited by a moderator:

Hudell

Dog Lord
Veteran
Joined
Oct 2, 2014
Messages
3,545
Reaction score
3,715
First Language
Java's Crypt
Primarily Uses
RMMZ
Add this script to your project

# ConfigFile for VXAce by Hudell# Free for non commercial and commercial use# Contact : brian@hudell.com# URL: www.hudell.commodule ConfigFile    SWITCHES_TO_LOAD = []    VARIABLES_TO_LOAD = []    @fileName = './Game.ini'    GetPrivateProfileString   = Win32API.new('kernel32', 'GetPrivateProfileString'  , 'ppppip'      , 'i')    WritePrivateProfileString = Win32API.new('kernel32', 'WritePrivateProfileString', 'pppp'        , 'i')      def self.getValue(section, option_name, defaultValue)        buffer = [].pack('x256')        print section.to_s + ", " + option_name.to_s + ", " + defaultValue.to_s + "\n"        value = GetPrivateProfileString.call(section, option_name, defaultValue, buffer, buffer.size, @fileName)        return buffer[0, value]    end    def self.setValue(section, option_name, value)        WritePrivateProfileString.call(section, option_name, value.to_s, @fileName)    end    def self.save_variable(variable_index)        setValue('variable', variable_index.to_s, $game_variables[variable_index])    end    def self.load_variable(variable_index)    value = getValue('variable', variable_index.to_s, $game_variables[variable_index].to_s)        $game_variables[variable_index] = value.to_i    end    def self.save_switch(switch_index)        if $game_switches[switch_index]            value = "1"        else            value = "0"        end        setValue('switch', switch_index.to_s, value)    end    def self.load_switch(switch_index)        if $game_switches[switch_index]            value = "1"        else            value = 0        end        value = getValue('switch', switch_index.to_s, value)        if value == "1"            $game_switches[switch_index] = true        else            $game_switches[switch_index] = false        end    end    def self.auto_load_stuff    SWITCHES_TO_LOAD.each do |switch_index|      load_switch(switch_index)    end    VARIABLES_TO_LOAD.each do |variable_index|      load_variable(variable_index)    end    endendclass Game_System    alias :global_switches_on_after_load :on_after_load  def on_after_load    global_switches_on_after_load    ConfigFile::auto_load_stuff  end    endAnd you can use those script calls to save and load values from the Game.ini file:

Save the value of variable 20:

ConfigFile.save_variable(20)Load the value of variable 20:

ConfigFile.load_variable(20)Save the state of switch 30

ConfigFile.save_switch(30)Load the state of switch 30

Code:
ConfigFile.load_switch(30)
 
Last edited by a moderator:

Prescott

argggghhh
Veteran
Joined
Aug 28, 2014
Messages
506
Reaction score
422
First Language
English
Primarily Uses
RMMV
Wow Hudell, that's freaking awesome. One question though, I can load it through a script call, but how do I know what the value is? Like, how do I tell if the switch is off or on, or what the variable is?
 

Hudell

Dog Lord
Veteran
Joined
Oct 2, 2014
Messages
3,545
Reaction score
3,715
First Language
Java's Crypt
Primarily Uses
RMMZ
The same way you do with any other switch or variable. There's no difference between them.
 

Prescott

argggghhh
Veteran
Joined
Aug 28, 2014
Messages
506
Reaction score
422
First Language
English
Primarily Uses
RMMV
Ohp. I'm stupid, don't listen to me xD xD

And these will be the same no matter what save file you are using, correct? :) this is pretty dang awesome if it works :)
 

Hudell

Dog Lord
Veteran
Joined
Oct 2, 2014
Messages
3,545
Reaction score
3,715
First Language
Java's Crypt
Primarily Uses
RMMZ
Ohp. I'm stupid, don't listen to me xD xD

And these will be the same no matter what save file you are using, correct? :) this is pretty dang awesome if it works :)
Yes, you just need to call the "load_switch" function to load the value from the Game.ini file to the switch.

I can make it load it automatically everytime you load the game, do you want me to do that?
 

Prescott

argggghhh
Veteran
Joined
Aug 28, 2014
Messages
506
Reaction score
422
First Language
English
Primarily Uses
RMMV
Yeah that would be fantastic! Absolutely perfect mate! You've definitely got a area in my credits x)
 

Hudell

Dog Lord
Veteran
Joined
Oct 2, 2014
Messages
3,545
Reaction score
3,715
First Language
Java's Crypt
Primarily Uses
RMMZ
I updated the script on the previous post. All you need to do is to configure which switches and which variables should be loaded automatically

just insert the number of the switch / variable here:

    SWITCHES_TO_LOAD = []    VARIABLES_TO_LOAD = []
like this:

Code:
    SWITCHES_TO_LOAD = [10, 20]    VARIABLES_TO_LOAD = [11, 21]
 

Prescott

argggghhh
Veteran
Joined
Aug 28, 2014
Messages
506
Reaction score
422
First Language
English
Primarily Uses
RMMV
Wow dude you're a life saver, thanks so much :D

This thread can be locked now :)
 

Murd

Apprentice
Member
Joined
Jan 28, 2015
Messages
112
Reaction score
7
First Language
Thai
Primarily Uses
I'm not quite sure that I understand correctly about the script. Please correct if I'm wrong.

Suppose, I have set v[10] to be auto-saved. Continuing from a saved file, at any point of time in my game that v[10] is set to x, so I just quit the game without saving (basically without this script, v[10] will be original value not x). Then reload the saved file and I'll see that v[10] is still x and the variable's value will be carried on to all saved files.

Am I correct? Sorry for my bad english.
 

Hudell

Dog Lord
Veteran
Joined
Oct 2, 2014
Messages
3,545
Reaction score
3,715
First Language
Java's Crypt
Primarily Uses
RMMZ
They are not auto-saved, only auto-loaded.

You need to call

ConfigFile.save_variable(10)
after changing it's value in order to save it.
 

Murd

Apprentice
Member
Joined
Jan 28, 2015
Messages
112
Reaction score
7
First Language
Thai
Primarily Uses
They are not auto-saved, only auto-loaded.

You need to call

ConfigFile.save_variable(10)after changing it's value in order to save it.
Ok clearly understand now. Very handy script you have made. Thank you!

I'm planning to have Instance dungeon mode like World of Warcraft in my project. It is kind of the same dungeon you have already completed with more difficult and challenge, boss hunts for better gears. But I want to have some wait time after each access to the dungeon and try to find a way to keep variable across all saved files to prevent restless hunting (bosses don't drop my gears so let's reload from previous saved file).
 

ArkDG

Veteran
Veteran
Joined
May 26, 2013
Messages
143
Reaction score
48
First Language
portuguese
Primarily Uses
@Hudell , your script is not working for Arrays... Is there any help you could give me?
 
Status
Not open for further replies.

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

  • Orin

Latest Threads

Latest Profile Posts

People3_5 and People3_8 added!

so hopefully tomorrow i get to go home from the hospital i've been here for 5 days already and it's driving me mad. I miss my family like crazy but at least I get to use my own toiletries and my own clothes. My mom is coming to visit soon i can't wait to see her cause i miss her the most. :kaojoy:
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.

Forum statistics

Threads
105,868
Messages
1,017,083
Members
137,583
Latest member
write2dgray
Top