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

xizorandy

Veteran
Veteran
Joined
Jan 31, 2015
Messages
53
Reaction score
15
First Language
English
Primarily Uses
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

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.
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,098
Reaction score
13,704
First Language
English
Primarily Uses
RMMV
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)
 

xizorandy

Veteran
Veteran
Joined
Jan 31, 2015
Messages
53
Reaction score
15
First Language
English
Primarily Uses
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
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,098
Reaction score
13,704
First Language
English
Primarily Uses
RMMV
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]
 
Last edited by a moderator:

xizorandy

Veteran
Veteran
Joined
Jan 31, 2015
Messages
53
Reaction score
15
First Language
English
Primarily Uses
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 :D
 

Tsukihime

Veteran
Veteran
Joined
Jun 30, 2012
Messages
8,564
Reaction score
3,846
First Language
English
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?
 

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

Latest Threads

Latest Posts

Latest Profile Posts

How many parameters is 'too many'??
Yay, now back in action Happy Christmas time, coming back!






Back in action to develop the indie game that has been long overdue... Final Fallacy. A game that keeps on giving! The development never ends as the developer thinks to be the smart cookie by coming back and beginning by saying... "Oh bother, this indie game has been long overdue..." How could one resist such? No-one c
So I was playing with filters and this looked interesting...

Versus the normal look...

Kind of gives a very different feel. :LZSexcite:
To whom ever person or persons who re-did the DS/DS+ asset packs for MV (as in, they are all 48x48, and not just x2 the pixel scale) .... THANK-YOU!!!!!!!!! XwwwwX

Forum statistics

Threads
105,849
Messages
1,016,981
Members
137,563
Latest member
cexojow
Top