Switch State Saver

parkman202

Warper
Member
Joined
Jan 10, 2015
Messages
2
Reaction score
0
First Language
English
Primarily Uses
Hello all!


For a while now, I've been facing a predicament with the development of my game, and that predicament is the requirement of a specific script from a game I was making in RPG Maker XP and want to convert to MV. I want to note that the script I have for the XP version was custom made, and the original coder didn't know how to convert it to Javascript.


So, this script will be hard to explain the function of because I explain things horribly when typing them out, so bare with me. xD


I should also note that I am using a script that skips the title (basically, it starts a new game on startup).


This script would act as a "mini New Game+" script per se, but it would save only specified switches. What do I mean? Basically, any specified switch IDs in the plugin's settings, lets say switch IDs 1 and 2, would have their state saved into a file or into something that could be detected at startup. I don't mean that I want them defaultly set to "ON" at startup, but that if at any point in the game is switch 1 or switch 2 changed from "ON" to "OFF" or "OFF" to "ON" using the normal "Control Switches" event command, it would be noted by the file and loaded on subsequent startups. I'll give a scenario for example, in which switch ID 3 is used by the plugin:


The player starts a new game and walks up to an event, and the event gives the player an item and the event ends with activating switch 3. This makes the event use the second page that will show the text "there's nothing here" if the player were to interact with it after receiving the item. If the player closes the game without saving, and reopens the game and begins the game again, they would go up to the event to find the "there's nothing here" text despite not manually saving and continuing. Think of it as fourth-wall breaking.


For another example, I'll look at the game Undertale. If you have just started the game and gone through a little ways, Toriel will ask your preference for the pie (cinnamon or butterscotch). If you tell her and then begin a new game a bit later, she will remember your choice even though you just started a new game.


Sorry If I was repeating myself a lot, it's just that I've asked many people before and they couldn't understand it too well (I don't blame them xD). If anyone is willing to help and requires better explanation, I will gladly try my best! :)


In case it helps, here is my title skipping script for MV:


/*:
* @plugindesc Skip the title scene for testing purpose.
* @version 1.0
*/

(function() {

Scene_Boot.prototype.start = function() {
Scene_Base.prototype.start.call(this);
SoundManager.preloadImportantSounds();
if (DataManager.isBattleTest()) {
DataManager.setupBattleTest();
SceneManager.goto(Scene_Battle);
} else {
this.checkPlayerLocation();
DataManager.setupNewGame();
SceneManager.goto(Scene_Map);
}
this.updateDocumentTitle();
};

})();


And here's the original script for XP:


#==============================================================================
# ** C O N F I G U R A T I O N
#==============================================================================
module SwitchSaving

# Choose switch IDs that you want applied upon starting the game. Can choose
# individual IDs or a range of them (i.e. x..y).
APPLY_CHANGES = [51, 52]

# Switch states will be saved to this file. Extension (.rxdata) not needed.
FILENAME = "SaveGame"

end
#==============================================================================
# ** Game_Switches
#------------------------------------------------------------------------------
# This class handles switches. It's a wrapper for the built-in class "Array."
# Refer to "$game_switches" for the instance of this class.
#==============================================================================
class Game_Switches
#--------------------------------------------------------------------------
# * Set Switch
# switch_id : switch ID
# value : ON (true) / OFF (false)
#--------------------------------------------------------------------------
alias save_switches_upon_set []=
def []=(switch_id, value)
save_switches_upon_set(switch_id, value)
# If setting a switch to TRUE
if value
file = File.open(SwitchSaving::FILENAME + ".rxdata","wb")
Marshal.dump($game_switches, file)
file.close
end

end
end
#==============================================================================
# ** Scene_Title
#------------------------------------------------------------------------------
# This class performs title screen processing.
#==============================================================================
class Scene_Title
#--------------------------------------------------------------------------
# * Command: New Game
#--------------------------------------------------------------------------
alias load_game_switches_on_new_game main
def main
load_game_switches_on_new_game
if FileTest.exist?(SwitchSaving::FILENAME + ".rxdata")
file = File.open(SwitchSaving::FILENAME + ".rxdata","rb")
switches = Marshal.load(file)
SwitchSaving::APPLY_CHANGES.each{|id|
if id.is_a?(Range)
id.each{|i| $game_switches = switches }
else
$game_switches[id] = switches[id]
end
}
end

end
end


Thank you for reading my very long and confusing post, and bless you if you can help me! ;)
 

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

Latest Threads

Latest Profile Posts

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.
Do you Find Tilesetting or Looking for Tilesets/Plugins more fun? Personally I like making my tileset for my Game (Cretaceous Park TM) xD

Forum statistics

Threads
105,868
Messages
1,017,074
Members
137,578
Latest member
JamesLightning
Top