Misplaced Variables and Switches

Hello, here with a very unusual problem.


So setting variables and switches works fine mid-game, but when I was trying to set variables at the start by placing $game_variables[x] and $game_switches[x], all sorts of horrible things happen.


Activating switch 1 for example activates switch 141 instead, and setting a variable on variable 30 for example sets it on variable 28 instead.


I'm also using a title screen skip.


Is there anything that may be causing this? I'm trying to disable my scripts one by one to root out the problem, but how is this happening?
you need to give us more info to help.


The usual way to set variables at the start is to have an autorun with control variables on the starting map - that always works correctly.


If you're setting the variables by script, you need to make sure to only set them after they are defined - which usually happens after the new game function is selected on the regular title menu.


So yes, your skip title can have caused your declaration to happen before the variable structure is initialised, and that can cause such problems.


But for a detailed bughunt, we need to get your deteils on scripts and where/how/when you're setting the variables.
Ah, sorry about that-


This is how the Skip Title script is set up (I modified it a little bit from Melosx's script)

Spoiler
#==============================================================================
# ** Skip_Title
#==============================================================================
# Author: Melosx
# Version: 1.0 => 7/12/2011
# Release Date: 7/12/2011
#
#------------------------------------------------------------------------------
# Instructions:
# Copy this script under Materials and above Main. You MUST fill in the SETUP
# section with the proper values for your project. Else your journey could
# start in the wrong place.
#==============================================================================
class Skip_Title < Scene_Base

#---------------------------------SETUP/--------------------------------#
ID_MAPPA = 1 # ID of the map where your Player's Starting Point is
COORDINATE_XY = [8, 6] # Player Starting Point X & Y cohordinates. [x,y]
#----------------------------------/SETUP---------------------------------#

def main
start
end

def start
SceneManager.clear
DataManager.load_database
DataManager.setup_new_game
DataManager.setup_starting_variables
$game_party.setup_starting_members
$game_map.setup(ID_MAPPA)
$game_player.moveto(COORDINATE_XY[0],COORDINATE_XY[1])
$game_player.refresh
SceneManager.call(Scene_Map)
$game_map.autoplay
end
end

#==============================================================================
# ** SceneManager
#==============================================================================
module SceneManager

def self.first_scene_class
$BTEST ? Scene_Battle : Skip_Title
end
end

#==============================================================================
# ** Scene_System
#==============================================================================

class Scene_System < Scene_MenuBase

#--------------------------------------------------------------------------
# command_to_title
#--------------------------------------------------------------------------
def command_to_title
@loaded = true
fadeout_all
SceneManager.clear
DataManager.load_database
DataManager.setup_new_game
DataManager.setup_starting_variables
$game_party.setup_starting_members
$game_map.setup(1)
$game_player.moveto(8,6)
$game_player.refresh
SceneManager.call(Scene_Map)
$game_map.autoplay
end

end

#==============================================================================
# ** Scene_Gameover
#==============================================================================

class Scene_Gameover < Scene_Base

#--------------------------------------------------------------------------
# goto_title
#--------------------------------------------------------------------------
def goto_title
fadeout_all
SceneManager.clear
DataManager.load_database
DataManager.setup_new_game
DataManager.setup_starting_variables
$game_party.setup_starting_members
$game_map.setup(1)
$game_player.moveto(8,6)
$game_player.refresh
SceneManager.call(Scene_Map)
$game_map.autoplay
end

end



...and this is where setup_starting_variables was called

Spoiler
module DataManager

#--------------------------------------------------------------------------
# mew method: self.setup_starting_variables
#--------------------------------------------------------------------------

def self.setup_starting_variables

#---------------------------------------------
# SETUP FIRST VARIABLES/SWITCHES HERE
#---------------------------------------------
$game_variables[47] = 5
$game_switches[148] = true
#---------------------------------------------
# END SETUP
#---------------------------------------------

end

end # end of module DataManager



I tried commenting out $game_variables and $game_switches and then moving the set variable/switches on the autorun script, and even put a 30 frame wait beforehand, but it's still pointing to the wrong variables and switches.


I'd post my whole project file since it's sorta a non serious/non commercial game, but it has a lot of external scripts inside.
How many scripts do you have?


Do a global script search (Control + Shift + F) for $game_variables and then for $game_switches.  That will give you a list of all scripts that use variables and switches.  See which ones are custom that you've added.  Disable those and see if the problem still happens.


At what point do you realise it's set the wrong variables?  Have the RIGHT variables been set as well?  Is it possible there's something else that's setting them in addition to what you're doing?  If you comment out your commands, are those other variables still being set?  Just trying to determine whether it really has anything to do with what you're doing - I suspect it's possible it's something else altogether and you're just assuming the two are related.
How many scripts do you have?


Do a global script search (Control + Shift + F) for $game_variables and then for $game_switches.  That will give you a list of all scripts that use variables and switches.  See which ones are custom that you've added.  Disable those and see if the problem still happens.


At what point do you realise it's set the wrong variables?  Have the RIGHT variables been set as well?  Is it possible there's something else that's setting them in addition to what you're doing?  If you comment out your commands, are those other variables still being set?  Just trying to determine whether it really has anything to do with what you're doing - I suspect it's possible it's something else altogether and you're just assuming the two are related.



Around 30+, but I disabled most of them and it's still causing the problem.


As for how I realized its' the wrong variables, I used F9 to check the variables at the start


$game_variables[47] = 5
$game_switches[148] = true


This line of code gave me


[IMG]http://puu.sh/qyFXP/e382b7d95e.jpg[/IMG]


at the start. As you can see, changing 47 changes 45 instead. I tried commenting that out and placing a set variable on the autorun event instead, but it still gave me the same result, even when I put a 30 frame wait beforehand.


But later on in the same event, this variable gets set properly.


[IMG]http://puu.sh/qyG5k/c28a911654.png[/IMG]


[IMG]http://puu.sh/qyG46/cef595ce1c.jpg[/IMG]


As for new info, I gave my copy of the project file to a friend to check, and his variables end up in the correct place when he used F9, even though he didn't change anything, even told him to check the variable on a clean unpack of the files I gave him and it's working fine.


It's not OS/Locale related because we're both using Japanese locale and Windows 10...

Spoiler
https://mega.nz/#!CAkXgIYT!FmLJqV5rwLK3TVsXKzLVnjujYG-dEY10sY8Owd4YHRI


The project file if anyone wants to try to debug it and see if it's causing the same error.
I'll take a look.


Edit: 30+?  Try 186!  In which of your 186 scripts have you added these lines to set the variables?


I play it and it works.  Where did you get your version of Ace?  It looks like the project was made with a pirated version, and this wouldn't be the first time people have encountered problems because they're using a pirated version.  It would also explain why it's happening to you and not your friend (or me).
I'll take a look.


Edit: 30+?  Try 186!  In which of your 186 scripts have you added these lines to set the variables?


I play it and it works.  Where did you get your version of Ace?  It looks like the project was made with a pirated version, and this wouldn't be the first time people have encountered problems because they're using a pirated version.  It would also explain why it's happening to you and not your friend (or me).

I'm using the steam version, actually


[IMG]http://puu.sh/qzqnt/80f28d86c8.jpg[/IMG]


I revalidated my steam copy once and reinstalled twice, and it doesn't work still.


Starting Variables is the name of the script that adds the variables.
I don't know what to say - the problem isn't happening for me.  Makes it kind of hard to track down.  I can't give you any other sugggestions.
🙁 I'm wondering if it has anything to do with my steam account or another program running that's causing it to malfunction.


Is there a way I can email the developers for help? Do they still even give support for VX Ace anymore?
very unlikely


Copy the Main script and paste it above ALL the custom scripts.  See if it still does it.  If it doesn't, it could be a script problem, but I would expect that anyone else running the game would have the issue as well.  Whether it does it or not, delete the pasted Main script then so only the original one remains.
very unlikely


Copy the Main script and paste it above ALL the custom scripts.  See if it still does it.  If it doesn't, it could be a script problem, but I would expect that anyone else running the game would have the issue as well.  Whether it does it or not, delete the pasted Main script then so only the original one remains.



It crashed when I did that. (Understandably)


The thing is the exported copies of my game that came from my computer has broken variables while the freshly re-exported ones from other computers somehow fixes it.


It's a very strange problem and it's making my head hurt.
I don't understand any of that, and putting Main above the other CUSTOM scripts should definitely not make your game crash.  You didn't put it RIGHT at the top of the list did you?  I did say above custom scripts, not all scripts.
I don't understand any of that, and putting Main above the other CUSTOM scripts should definitely not make your game crash.  You didn't put it RIGHT at the top of the list did you?  I did say above custom scripts, not all scripts.

[IMG]http://puu.sh/qzss8/2ab7e8745f.png[/IMG]


it's probably because i modified some of the default scripts, so that's understandable


i'm going to try the variables thing on a fresh project


edit:


it works. i don't know what's going on anymore


also, what i meant was...


the game.exe file that comes from my computer has the error


if other computers playtest and generate another game.exe file,


it doesn't have the error


edit:


welp, I probably found where the error lies.


when i call another script (global_load) it apparently moves those certain variables/switches into other spots


the question of why it's doing that on other computers and not on mine is another thing entirely

Spoiler
#==============================================================================
# # Global Save System [v1.0]
# # By theLEECH
#==============================================================================
# # Overwrites:
# # in module DataManager:
# # # self.load_game(index)
# # # self.save_game(index)
# # # self.setup_new_game
#==============================================================================
# ---INSTRUCTIONS---
# Put the numbers of the variables to save and the switches to save in the
# VARIABLES_TO_SAVE array, and the SWITCHES_TO_SAVE array.
# If you want to automatically load/update the globally saved data, set the
# SAVE_ON_SAVE LOAD_ON_LOAD and LOAD_ON_NEW flags to true accordingly.
#------------------------------------------------------------------------------
# You can load and save global data within an event, by using the script command
# and entering: "global_save" or "global_load" (Without qoutations)
#==============================================================================
#==============================================================================
# # LGlobalSave
#==============================================================================
module LGlobalSave

#==============================================================================
# CONFIGURATION
#==============================================================================
# Whether or not the variables and switches in the global file should be
# saved when the player saves the game
SAVE_ON_SAVE = true
# Whether or not the variables and switches in the global file should be
# loaded when the player loads a save file
LOAD_ON_LOAD = true
# Whether or not the variables and switches in the global file should be
# loaded when the player starts a new game
LOAD_ON_NEW = true
# An array that contains a list of variables to save in the global save file
# Enter a list of variables, by number, seperated by commas.
# You can use '..' to include all variables between two numbers
# Example: 15..42
# Will include all variables or switches between 15 and 42 (inclusive)
# Leave blank to save none of that type
VARIABLES_TO_SAVE = [12..14, 207..208]
# Same as above, but for switches
SWITCHES_TO_SAVE = [81..84, 145, 283, 401..500]
# The name of the file to save global variables and switches in
FILE_NAME = "Global.rvdata2"
#==============================================================================
# END OF CONFIGURATION
#==============================================================================

def self.saveTheFile(f)
File.open(FILE_NAME, "wb") do |file|
Marshal.dump(f, file)
end
end

def self.loadTheFile
if !File.exists?(LGlobalSave::FILE_NAME)
f = makeNewFile
return f
else
f = nil
File.open(FILE_NAME, "rb") do |file|
f = Marshal.load(file)
end
return f
end
end

def self.makeNewFile
return LGlobalSaveFile.new
end

def self.loadVariables(f)
for i in VARIABLES_TO_SAVE
$game_variables= f.getVar(i)
end
end

def self.loadSwitches(f)
for i in SWITCHES_TO_SAVE
$game_switches= f.getSwitch(i)
end
end

def self.saveVariables(f)
for i in VARIABLES_TO_SAVE
f.setVar(i, $game_variables)
end
end

def self.saveSwitches(f)
for i in SWITCHES_TO_SAVE
f.setSwitch(i, $game_switches)
end
end

def self.save
f = makeNewFile
saveVariables(f)
saveSwitches(f)
saveTheFile(f)
end

def self.load
f = loadTheFile
loadVariables(f)
loadSwitches(f)
end

end # end of module LGlobalSave

#==============================================================================
# ** LGlobalSaveFile
#------------------------------------------------------------------------------
# An object of this class is saved in the global.sav file
# It contains all the saved variables and switches
#==============================================================================
class LGlobalSaveFile

def initialize # Initializes the object
@var = []
@switch = []
end

# @var holds the saved variables
# set and get methods:
def getVar(id)
return @var[id]
end
def setVar(id, val)
@var[id] = val
end

# @switch holds the saved switches
# set and get methods:
def getSwitch(id)
return @switch[id]
end
def setSwitch(id, val)
@switch[id] = val
end

end # end of class LGlobalSaveFile

#==============================================================================
# These methods are for saving and loading the global save file from an event
#==============================================================================
def global_save
LGlobalSave.save
end
def global_load
LGlobalSave.load
end
#==============================================================================
# ** DataManager
#==============================================================================
module DataManager

#--------------------------------------------------------------------------
# overwrite method: self.setup_new_game
#--------------------------------------------------------------------------
def self.setup_new_game
create_game_objects
#~ $game_party.setup_starting_members
#~ $game_map.setup($data_system.start_map_id)
#~ $game_player.moveto($data_system.start_x, $data_system.start_y)
#~ $game_player.refresh
Graphics.frame_count = 0
LGlobalSave.load if LGlobalSave::LOAD_ON_NEW
$game_system.init_visvars
end

#--------------------------------------------------------------------------
# overwrite method: self.save_game(index)
#--------------------------------------------------------------------------
def self.save_game(index)
begin
save_game_without_rescue(index)
rescue
delete_save_file(index)
false
end
LGlobalSave.save if LGlobalSave::SAVE_ON_SAVE
end

#--------------------------------------------------------------------------
# overwrite method: self.load_game(index)
#--------------------------------------------------------------------------
def self.load_game(index)
load_game_without_rescue(index) rescue false
#LGlobalSave.load if LGlobalSave::LOAD_ON_LOAD
end
end # end of module DataManager






I fixed it by placing a global_save at the start of the game. Maybe it just breaks if it tries to load a global save that doesn't exist.


Sorry for all the trouble!

Original thread: https://forums.rpgmakerweb.com/threads/misplaced-variables-and-switches.66667/