Passing a MapID as the key to a Hash or Bit Switch

I'm still new, sorry if this is a noob question... I've managed to get the outcome I want using a heap of variables, but I don't like it - It's too messy for me. (also, sorry if I haven't got all the terms correct)

The Short Version of this question is:

Can I use the MapID as a key in a Hash? or Bit Switch?

I want to use a Hash to store the state of something on a map.

Please bear with me, I've re-written this so many times trying to make sure I've made myself understandable.

To simplify what I'm speaking of, lets say I have 50 maps that are parts of a maze.

  • Player is in Map3, they turn on the lights.
  • Later, in Map6, they trigger the lights in Map3 to be turned off.
  • When player enters Map3 again, I want the lights off.
I am trying to use CommonEvents (triggered by autorun) when I enter Map3 to check the light status and turn them on or off.

I am also trying to use a CommonEvent when I turn the lights on to save the state of the light (on or off)

Here's the 3 webpages I've been trying to learn from:

http://www.rpgmakervxace.net/topic/19191-hash-expressions/

http://ruby-doc.org/core-2.1.2/Array.html

https://himeworks.wordpress.com/2013/06/07/bit-switches/

I have found that I tend to make a mess, so before I start trying to make events, I try to write things out for myself in notepad to make sure my thoughts are in some kind of order, here's what I wrote for this process

Spoiler
Define Variable: CurrentLightState (True or False)

 

Define Array: MapLightState

Array Name: MapLightState

Array Key: MapID

Array Value: State (True or False)

 

 

Player Turns on lights: (assuming lights off)

#SetLightsOn (commands to turn on the lights)

Get Current MapID

Set State to: True

Write to array: MapLightState(MapID,True)

 

 

Upon Player entering a room:

Get Current MapID

CurrentLightState = MapLightState(MapID,?value?)

If CurrentLightState = True #SetLightsOn

else #SetLightsOff

 

 

SetLightsOn

#Commands to turn on lights

 

 

SetLightsOff

#commands to turn lights off

 

 

Player Turns off the lights: (if the lights are on)

#SetLightsOff

Get Current MapID

Set State to: False

Write to array: MapLightState(MapID,False)

 

 

Repeate defining arrays to track other Map environment states: posioned air, dread, infestation

 


If I have it right, I define the variable as a hash: MapLightState= {}

 

and when the player turns on the lights, I get the MapID into a variable with: Control Variables [0001:CurrentMap] = Map ID

 

and then set another variable with the current light state Control Variables [0002:CurrentLightState] = 1

 

And here is where I get stuck.

 

How can I pass the variables to be the contents of the hash?

 

How do I read the correct value back when the player enters a room?

 

 

I included the link above for Bit Switches - It looked promising and I was interested in using it as setting or calling a True/False value looked nice and easy: set_bit_switch(MapLightState, MapID, True)

 

I just hit the same issue of how to pass it the MapID of my current map, or the ID of a Map I want to change a state in.
Is there a reason you can't just use switches for this?


Switch [001: Room 3 Lights]


When in room 3, player turns lights on (switch 1 = ON)


When in room 6, player triggers lights in room 3 to be off (switch 1 = OFF)


When back in room 3, lights are off (because they're conditioned by switch 1)
It was getting messy using switches and variables.

I simplified what I was doing for the post, but there are 8 environment states that could be applied to a map. Maybe it's just the way that my brain works, but I would find it easier to track using a set of Hashes or the Bit Switch
You can use a number as a hash key.


If you want the current map, it's $game_map.map_id. Otherwise just use a number.


To access a variable in script, it's $game_variables[id]


So if you want to set map 5's value to whatever is in variable 15, it'd be MapLightState[5] = $game_variables[15]
Thanks Shaz, I'll keep playing with this... there's gotta be a easier way to track this without using a myriad of switches and variables, but I'm not sure what it is yet 😀
It was getting messy using switches and variables.


I simplified what I was doing for the post, but there are 8 environment states that could be applied to a map. Maybe it's just the way that my brain works, but I would find it easier to track using a set of Hashes or the Bit Switch
Why was it getting messy?

Original thread: https://forums.rpgmakerweb.com/threads/passing-a-mapid-as-the-key-to-a-hash-or-bit-switch.38527/