How do I fix these lines?

Started by cessern, January 20, 2015, 06:58:21 am

Previous topic - Next topic

cessern

January 20, 2015, 06:58:21 am Last Edit: January 20, 2015, 11:03:57 pm by KK20
(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 :/

ForeverZer0

Looks like your going about this all wrong, you shouldn't even need to edit any scripts. Why not just use different variables?
I am done scripting for RMXP. I will likely not offer support for even my own scripts anymore, but feel free to ask on the forum, there are plenty of other talented scripters that can help you.

cessern

January 20, 2015, 11:48:44 am #2 Last Edit: January 20, 2015, 11:04:10 pm by KK20
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.

KK20

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).

Other Projects
RPG Maker XP Ace  Upgrade RMXP to RMVXA performance!
XPA Tilemap  Tilemap rewrite with many features, including custom resolution!

Nintendo Switch Friend Code: 8310-1917-5318
Discord: KK20 Tyler#8901

Join the CP Discord Server!

cessern

January 21, 2015, 01:43:04 am #4 Last Edit: January 21, 2015, 01:44:22 am by cessern
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.

KK20

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

Other Projects
RPG Maker XP Ace  Upgrade RMXP to RMVXA performance!
XPA Tilemap  Tilemap rewrite with many features, including custom resolution!

Nintendo Switch Friend Code: 8310-1917-5318
Discord: KK20 Tyler#8901

Join the CP Discord Server!

cessern

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?

KK20

Probably because you're overwriting Global Switches and Variables script's methods
Code: Global S&V Script

  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.

Other Projects
RPG Maker XP Ace  Upgrade RMXP to RMVXA performance!
XPA Tilemap  Tilemap rewrite with many features, including custom resolution!

Nintendo Switch Friend Code: 8310-1917-5318
Discord: KK20 Tyler#8901

Join the CP Discord Server!