• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Legacy GM need help with a switch puzzle

pixeltroid

Member
I made a very simple switch puzzle system to open certain doors. There are 4 switches (red, yellow, green, blue). The player stands near each switch and presses a button to turn it on and off. So once the player has the correct color combination (red and blue in the example) the door opens.



As of now, the player gets the information about the correct combination from a different area in the game. But I have now realized that it would be very easy for a player to "crack the code" simply by trying out various combinations on the switches. So I was thinking I could make the code harder to crack by requiring the switches to be turned on in a specific order.

Is there a way to achieve that?

Here are my codes for what I have right now.

Each of the colored switches on the ground have these codes:

Create
Code:
global.yellowswitch = true
Step 1 (changes sprite)
Code:
if global.yellowswitch = false
{
sprite_index = spr_yellowswitch1
}
else if global.yellowswitch = true
{
sprite_index = spr_yellowswitch2
}
Step 2 (changes value of switch)
Code:
if place_meeting(x,y,obj_player) && keyboard_check_pressed(ord("L"))
{
if global.yellowswitch = true
{
global.yellowswitch = false
}

else if global.yellowswitch = false
{
global.yellowswitch = true
}
}

The switch control object on the top has these codes:

Step(checks if the switches are in the correct combination):
Code:
if room = room_T1 && global.yellowswitch = false && global.redswitch = true && global.greenswitch = false && global.blueswitch = true
{
global.switchcontroller[1] = true
}
Creation code:
Code:
switchcontoller_id = 1
So basically if global.switchcontroller becomes "true", the door object with the corresponding ID in the creation code gets removed out of the way.

My question is: How do I make it so the code works only if the switches are turned on in a specific order? So for example, it would have to be blue, green and red in that order otherwise it wont work.

Any help would be appreciated.
 

QueSonoZZZ

Member
colored switches

Step 2 (changes value of switch)
Code:
if place_meeting(x,y,obj_player) && keyboard_check_pressed(ord("L"))
{
if global.yellowswitch = true
{

global.yellowswitch = false
}

else if global.yellowswitch = false
{
global.yellowswitch = true
}
yellow_time = date_current_datetime(); :)
}

switch control object

Step(checks if the switches are in the correct combination):
Code:
if room = room_T1 && global.yellowswitch = false && global.redswitch = true && global.greenswitch = false && global.blueswitch = true
{
if (date_compare_date(global.yellow_time, global.red_time) == -1) and
(date_compare_date(global.red_time, global.green_time) == -1) and
(date_compare_date(global.green_time, global.blue_time) == -1) then:)
{
global.switchcontroller[1] = true
}
}
:squirrel::squirrel::squirrel::squirrel::squirrel::squirrel::squirrel::squirrel:
 

pixeltroid

Member
colored switches

Step 2 (changes value of switch)
Code:
if place_meeting(x,y,obj_player) && keyboard_check_pressed(ord("L"))
{
if global.yellowswitch = true
{

global.yellowswitch = false
}

else if global.yellowswitch = false
{
global.yellowswitch = true
}
yellow_time = date_current_datetime(); :)
}

switch control object

Step(checks if the switches are in the correct combination):
Code:
if room = room_T1 && global.yellowswitch = false && global.redswitch = true && global.greenswitch = false && global.blueswitch = true
{
if (date_compare_date(global.yellow_time, global.red_time) == -1) and
(date_compare_date(global.red_time, global.green_time) == -1) and
(date_compare_date(global.green_time, global.blue_time) == -1) then:)
{
global.switchcontroller[1] = true
}
}
:squirrel::squirrel::squirrel::squirrel::squirrel::squirrel::squirrel::squirrel:

thanks I'll try it out now. :)
 

pixeltroid

Member
if (date_compare_date(global.yellow_time, global.red_time) == -1) and
(date_compare_date(global.red_time, global.green_time) == -1) and
(date_compare_date(global.green_time, global.blue_time) == -1) then:)
{
global.switchcontroller[1] = true
}
}
okay I'm not sure I get how this works.

if I need the switches to be activated in the order of red, blue and yellow or something else how do I re-write the above code?
 

QueSonoZZZ

Member
http://docs2.yoyogames.com/source/_...ce/maths/date and time/date_compare_date.html

date_compare_date



Description
With this function you can check two dates to see which one is the earlier or later than the other. The function returns -1 if date1 is earlier, 0 if both dates are the same, and 1 if date1 is later.



Syntax:
date_compare_date( date1, date2 );



Argument Description
date1 The first date.
date2 The date to compare it to.


Returns:
Real



Example:
d = date_compare_date(date_create_datetime(2011, 9, 15, 11, 4, 0), date_current_datetime());

This would set "d" to the corresponding value depending on which of the dates was the earliest, likely 1 since the current date would be further ahead than 15th September 2011.

:squirrel::squirrel::squirrel::squirrel::squirrel::squirrel::squirrel::squirrel::squirrel::squirrel::squirrel::squirrel::squirrel::squirrel::squirrel:
 

pixeltroid

Member
QueSonoZZZ I really appreciate your help. But I just changed the concept a while back.

Now instead of making the "password" a specific combination of colors pressed in a chronological order, I'm going for the old fashioned numerical password system. I think it will be easier for me to implement this system across many rooms.

Now, each switch will display a number, so player need to get the correct 4 digit number to open the door. This way, it is still difficult for players to guess the correct password. And I figure its also less confusing for the player.


switch_num.gif

So the code to check the password would look something like:

Code:
if room = room_T1 && global.yellowswitch = 4 && global.redswitch = 3 && global.greenswitch = 1 && global.blueswitch = 2
{
global.switchcontroller[1] = true
}
I'm quite happy with this and I'll stick to it!
 
Top