Hey gang,
Recently I've made myself a nice little cheat menu that quickly enables me to test certain portions of my game. I can set the initial visibility to true/false no dramas in the main menu. It works a charm.
However, often I forget to turn the GUI off when compiling and have subsequently had the yucky looking cheat GUi showing in the main menu when showing off my game.
I would like to somehow script the GUI to turn visible only when pressing a key combination (eg. Shift + Z + P) for instance. QUALITY OF LIFE.
I have been perusing the manual and the "IsKeyPressed" function is looking fruitful. I could place this in the repeatedly execute for that room (main menu).
I am to understand that this however, doesn't allow key combinations -
KEYCODE is one of the ASCII codes, with some limitations: since it tests the raw state of the key, you CANNOT pass the Ctrl+(A-Z) or Alt+(A-Z) codes (since they are key combinations). You can, however, use some extra codes which are listed at the bottom of the section.
Is there in fact a way to do this?? Any help greatly appreciated. :)
You could try testing several keys altogether:
if (IsKeyPressed(eKeyZ) && IsKeyPressed(eKeyP) && (IsKeyPressed(403) || IsKeyPressed(404))))
In case you did not know, && means logical and , || means logical or
403 and 404 are left shift and right shift respectively. I found this info in the manual ("ASCII code table" article), apparently they do not have named constants in AGS, but you may define them for convenience:
// Somewhere in the global header
#define LEFT_SHIFT 403
#define RIGHT_SHIFT 404
// The key test code
if (IsKeyPressed(eKeyZ) && IsKeyPressed(eKeyP) && (IsKeyPressed(LEFT_SHIFT) || IsKeyPressed(RIGHT_SHIFT))))
Example on key press(s) in Global
if (keycode ==eKeyCtrlA) { // CTRL + A
gTablet.Visible = true;
}
AGS KeyCode Key ASCII code
eKeyNone none 0
eKeyCtrlA Ctrl+A 1
eKeyCtrlB Ctrl+B 2
eKeyCtrlC Ctrl+C 3
eKeyCtrlD Ctrl+D 4
eKeyCtrlE Ctrl+E 5
eKeyCtrlF Ctrl+F 6
eKeyCtrlG Ctrl+G 7
eKeyCtrlH Ctrl+H 8
eKeyCtrlI Ctrl+I 9
eKeyCtrlJ Ctrl+J 10
eKeyCtrlK Ctrl+K 11
eKeyCtrlL Ctrl+L 12
eKeyCtrlM Ctrl+M 13
eKeyCtrlN Ctrl+N 14
eKeyCtrlO Ctrl+O 15
eKeyCtrlP Ctrl+P 16
eKeyCtrlQ Ctrl+Q 17
eKeyCtrlR Ctrl+R 18
eKeyCtrlS Ctrl+S 19
eKeyCtrlT Ctrl+T 20
eKeyCtrlU Ctrl+U 21
eKeyCtrlV Ctrl+V 22
eKeyCtrlW Ctrl+W 23
eKeyCtrlX Ctrl+X 24
eKeyCtrlY Ctrl+Y 25
eKeyCtrlZ Ctrl+Z 26
Thanks guys, making a bit of sense now. I am having trouble implementing the code however.
Both instances I get a Parse error: unexpected 'if'.
I'm placing the code into the global header.
It's not suppose to go on the header, but on the script under the function called "on_key_press"
'if' is used within a function as a condition of that function.
in your case:
on_key_press is the function (built into Global.asc)
if key(s) pressed is the condition
@Nixxon, in your first post you said that you were going to put the key detection code into repeatedly execute of the room, so I figured I do not need to mention where to put it.
You may as well put the code in the on_key_press, but you still won't be able to check 3 keys combination using only "keycode" variable, you would still need to use IsKeyPressed to know if other keys are pressed (e.g. Shift key).
Really odd, I've replaced one of the lines in the // debug functions just as a start and it doesn't seem to to work at all.
No big deal, I might just make a small transparent UI somewhere I can click on to bring up the menu.
// DEBUG FUNCTIONS
if (keycode == eKeyCtrlS) Debug(0,0); // Ctrl-S, give all inventory
if (keycode == eKeyCtrlV) Debug(1,0); // Ctrl-V, version
if (keycode == eKeyCtrlA) gcheat.Visible = true; // Ctrl-A, show cheat menu
if (keycode == eKeyCtrlX) Debug(3,0); // Ctrl-X, teleport to room
if (keycode == eKeyCtrlW && game.debug_mode)