I am trying to make a cheat that can be activated on the title screen similar to sonic mania
How would I add a cheat code to a title screen
what is the cheat code? last sonic i played was sonic pinball on sega gamegear in early 2000s
kuligs2 The sonic 3 level select cheat and I wanted it to enable debug mode
- Edited
Check for input events (key presses, clicks in certain locations, etc.), and activate the cheat if the correct inputs are received.
Reference:
https://docs.godotengine.org/en/4.2/tutorials/inputs/input_examples.html
If the cheat code is, for example, "iamtheone", you could start a 15-second Timer if an "i" is entered, and then accumulate additional key presses in a buffer until the buffer contains "iamtheone" (activate the cheat) or the Timer finishes (clear the buffer).
Another approach: When a specific sequence of locations are clicked within a time interval, pop up a LineEdit for entry of the cheat code.
DaveTheCoder No I want to use input maps
- Edited
Then use input maps.
There's an example here ("First, we need to check for input - is the player pressing a key?"):
https://docs.godotengine.org/en/4.2/getting_started/first_2d_game/03.coding_the_player.html#coding-the-player
DaveTheCoder It doesn't work
extends Node
var cheatCodes = {
"gm_up gm_up gm_down gm_down gm_up gm_up gm_up gm_up": "konami"
}
func _ready():
if Global.debug ==0:
if Input.is_action_just_pressed("gm_up") and Input.is_action_just_pressed("gm_up") and Input.is_action_just_pressed("gm_down") and Input.is_action_just_pressed("gm_down") and Input.is_action_just_pressed("gm_up") and Input.is_action_just_pressed("gm_up") and Input.is_action_just_pressed("gm_up") and Input.is_action_just_pressed("gm_up"):
Global.debug =1
$"../Node2D/AudioStreamPlayer2".play()
I think that only one Input.is_action_just_pressed() can be true.
What exactly is your cheat code? Pressing multiple keys in a sequence?
You need to check input in _input or _unhandled_input.
https://docs.godotengine.org/en/stable/tutorials/inputs/inputevent.html
And the way you wrote it, you check if ALL is pressed at once.
No I wanted it to check if the inputs are pressed one by one
Raptorkillz You should at least work through introductory tutorials in Godot docs before attempting anything else, to get some basic understanding of how things work.
xyz Okay but in the code there's this line
var cheatCodes = {
"gm_up gm_up gm_down gm_down gm_up gm_up gm_up gm_up": "konami"
}
Raptorkillz that is no konami master code. konami master code was
- Edited
Raptorkillz Okay but in the code there's this line
Yeah, but there are other lines as well
Here's an automatic class that listens to action sequences, and when it finds something, it notifies about that via a signal:
class_name CheatCodeListener extends Node
signal code_entered(name)
var s: String
var cheats = {"ui_up ui_down ui_up" : "some cheat", "ui_left ui_right" : "some other cheat"}
func _input(e):
for a in InputMap.get_actions().filter(func(aa): return e.is_action_pressed(aa)).slice(0,1):
s += a if not s else " " + a
for k in cheats.keys(): if s.contains(k): code_entered.emit(cheats[k]); s = ""
Now the only thing left to do is to make a game to cheat at. Easy peasy
xyz Okay but how would I make it play a sound
- Edited
Raptorkillz Okay but how would I make it play a sound
print(String.chr(0x07))
. But you'll need to start a console version of Godot for this to work.
xyz I am on mobile
Raptorkillz Well then you play it the same way you play the music. You already have that in the code you posted in one of your questions.