(Edited the script)
class Game_Variables
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize
@data = []
end
#--------------------------------------------------------------------------
# * Get Variable
# variable_id : variable ID
#--------------------------------------------------------------------------
def [](variable_id)
if variable_id <= 5000 and @data[variable_id] != nil
if $game_switches[223] == true
return @data[variable_id + 600]
else
return @data[variable_id]
end
else
return 0
end
end
#--------------------------------------------------------------------------
# * Set Variable
# variable_id : variable ID
# value : the variable's value
#--------------------------------------------------------------------------
def []=(variable_id, value)
if variable_id <= 5000
if $game_switches[223] == true
@data[variable_id + 600] = value
else
@data[variable_id] = value
end
end
end
end
I'm trying this, because I want to make map2 with new variables without map1 interferring with it. Its a two player game, and if both maps shares the same global variables, it will interfere with each other. So I want the other map to use a new sets of variables. Any help? You can see what I tried in the script. I believe it works but the Switch condition can't be read :/
Looks like your going about this all wrong, you shouldn't even need to edit any scripts. Why not just use different variables?
I can't do that. I knew someone would reply something like that. But if I were going to use different variables, I'll have to edit 100+ variables for each map. It would take too much time. Since Global switches/variables would make the maps interfere with each other.
class Game_Variables
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize
@data = []
end
#--------------------------------------------------------------------------
# * Get Variable
# variable_id : variable ID
#--------------------------------------------------------------------------
def [](variable_id)
if variable_id <= 5000 and @data[variable_id] != nil
if $game_switches[223] == true
return @data[variable_id + 600]
else
return @data[variable_id]
end
else
return 0
end
end
#--------------------------------------------------------------------------
# * Set Variable
# variable_id : variable ID
# value : the variable's value
#--------------------------------------------------------------------------
def []=(variable_id, value)
if variable_id <= 5000
if $game_switches[223] == true
@data[variable_id + 600] = value
else
@data[variable_id] = value
end
end
end
end
This seems more correct right? But the switches doesn't do anything. I've tested @data[variable_id + 600] = value without the script condition, and that solved my problem pretty much, but I want to be able to control when it happens.
My question is what in the world are you even trying to accomplish. Why does each map need a unique set of variables that can be referenced back to later? What about future maps? Are you going to do this exact same process for EVERY map in your game? If so, lemme just stop you there since you are clearly going in the absolute wrong direction (i.e. you'd get fired for doing this).
Think of it like this. I'm using global variables and such to indicate where things are spawned. About 100 of them have I used in this map. I'm trying to copy the map, but if all the maps used the same variables then one map will cause a spawn to another map. I'm trying to make those maps just spawn stuff on their own map. Its kind of a "lazy" solution, but I don't want to make 100 new variables every time I make a new map.
This game is a minigame thing. And I just want more Game slots. Its acctually going to be just the same map everytime yh.
Well I will confirm that the code does actually work. If you're checking the values of variables 600+, obviously you're not going to get the value you expect. Your Game_Variables#[] method is going to return whatever is 600 more of the variable you chose, assuming you are checking with switch 223 turned on. You should be turning it off if you want to compare variables X and X+600.
$game_variables[1] = 50
$game_switches[223] = true
$game_variables[1] = 25
$game_switches[223] = false
p $game_variables[1] #=> 50
p $game_variables[601] #=> 25
It doesn't work for me with global variables, I believe it may have to do with global variables acting differently than normal variables. It seemed to work when I did it on an empty project. If this is the wrong way to go, do you have any suggestions on what I should do?
Probably because you're overwriting Global Switches and Variables script's methods
alias set_gswivar_later []=
def []=(id, value)
if !$game_temp.disable_global && GLOBAL_VARIABLES.include?(id)
$network.send_variable(id, value)
else
set_gswivar_later(id, value)
end
end
You should be editing this method, not making a whole new rewrite.