• 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 Easy way to include a cheat code?

M

Mobie

Guest
Is there a simple way for me to include a secret cheat code that will open up a hidden feature in a game? I know how to do everything except create a user input variable to store a 3 digit code. Do I use "get_string"?
 
Last edited by a moderator:
L

Lonewolff

Guest
keyboard_string() maybe?

Code:
if string_length(keyboard_string) > 15
   {
   keyboard_string = string_copy(keyboard_string, 1, 15);
   }
Then just parse the string to see if the desired cheat code was entered.
 

samspade

Member
If it's just three digits then the simplest would just be this:

Code:
if (keyboard_check_pressed(ord("1"))) && (keyboard_check_pressed(ord("2"))) && (keyboard_check_pressed(ord("3"))) {
    cheat_on = true;
}
This requires holding all three at the same time, but if you wanted to make it sequential, you could just add a timer and a sequence as you would with any combo system. For example:

Code:
if (button_1 == false) && (keyboard_check_pressed(ord("1"))) {
     button_1 = true;
     //set a timer to turn off all buttons
}

if (button_1 == true) && (button_2 == false) && next key {
     button_2 = true;
     //reset timer 
}

//continue
Or something similar.
 

Ubu

Member
The simplest way would probably be:

Step event:
Code:
if string_pos("cht", keyboard_string)  // Change "cht" for your own 3 digit code
    show_debug_message("Cheat On");
This is also flexible, as your codes can be of different lengths.
 
Last edited:

TheouAegis

Member
Code:
if (keyboard_check_pressed(ord("1"))) && (keyboard_check_pressed(ord("2"))) && (keyboard_check_pressed(ord("3"))) {
cheat_on = true;
}
This requires holding all three at the same time
That requires all 3 being PRESSED at the same time, which is somewhat difficult at higher frame rates. Removed the _pressed parts and i would work more easily.


Anyway, the method i use for cheats is to have an array of inputs and a variable tracking how far the user is in the array. This way you can use non-character keys.

Code:
code[0]=vk_up
code[1]=vk_right
code[2]=vk_right

io_code = 0;
e.g.:
Code:
if UP_KEY
if code[io_code]==vk_up io_code++;
else io_code=0;

if io_code==array_length_1d(code) cheat_enabled=true;
 
M

Mobie

Guest
I wrote something pretty boneheaded but it seems to work.
Code:
if(keyboard_string == 3423)
{
instance_create(300,400,obj_secret_button);
keyboard_string = "";
}
 
Last edited by a moderator:

MilesThatch

Member
You can get the keyboard input as a string. you could also clear that string. Basically you can write a code to always check for a word "nuttertools" and when it sees it, it will spawn something
 
M

Mobie

Guest
You can get the keyboard input as a string. you could also clear that string. Basically you can write a code to always check for a word "nuttertools" and when it sees it, it will spawn something
Your post gave me the idea to rewrite my code to this below. Thank you.

Code:
if(keyboard_string == 3423)
{
instance_create(300,400,obj_secret_button);
keyboard_string = "";
}
 

Tornado

Member
About that solution with keyboard_string:
How can he know when he has a "clean string" (ie. "nuttertools") inside of keyboard_string?
If user pressed some keys before, then keyboard_string will already have some chars inside for example it will be then "qwertynuttertools", so the IF will never be true.
Shouldn't he then also need to have a key-press for deleting content of the keyboard_string first?
I guess only after purging the content of keyboard_string this can be TRUE:
if(keyboard_string == "nuttertools")
 
Last edited:
M

Mobie

Guest
About that solution with keyboard_string:
How can he know when he has a "clean string" (ie. "nuttertools") inside of keyboard_string?
If user pressed some keys before, then keyboard_string will already have some chars inside for example it will be then "qwertynuttertools", so the IF will never be true.
Shouldn't he then also need to have a key-press for deleting content of the keyboard_string first?
I guess only after purging the content of keyboard_string this can be TRUE:
if(keyboard_string == "nuttertools")
Yeah, that's a good idea. Maybe even a "start over" button that runs
keyboard_string = "";

Thank you, I'll do that.
 
Top