0 votes

I only recently began learning Godot and GDScript, so please bear with me here. I want to implement cheat codes into a game similar to how GTA does it, where you can type in a phrase and execute a function. I searched about this and I found various methods of doing it, but none of them explain clearly how it works and just throw code out.

Can anyone explain an efficient method of adding these cheat codes?

Godot version Godot v.3.2.3 64-bit Stable for Windows
in Engine by (19 points)
edited by

Have your cheat list stored with expected behaviors

The GTA Hidden way
When a key is pressed start a cheat-listener function

func is_cheating():
    Check if another key is pressed within a certain time
    else ignore and consider it as movement key

    If another key is pressed within expected time frame

    compare a concatenated String or Unicode to entries 
    in your stored cheat list

    if cheat is stored in list
    call cheat function with expected behavior

The Console/Promo-Code way
Have an input field for the code
when enter/accept pressed compare to stored code list
execute expected behavior

1 Answer

0 votes

LineEdit is a Node that let's your user put in some text. Pair it with a button that checks if the secret code is valid, and launch your function.
You can either put them in plain sight inside your interface, or hide them with a small TextureButton.

by (2,568 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.