This is an on-going project to make a command prompt type system in GMS.
I started with GMWolf's user input video (check it out its awesome and helpful)
It finds what character the user has typed and compares that to an allowed keys list. (more in GMwolfs video)
I then edited it using UTF-8 character codes to replace what the player has typed to that character in a string,
using this we can now allow for more advanced things to be done.
When the user presses inter it saves what they typed in a variable which holds the input string.
As of now it runs a chain of scripts to filter what commands have been typed and matches those words to a ds_grid holding the commands we want, then sets the value of the command to true in a different grid.
Once we have done that we read the grid and check how many are true, if more then one we give an error, if none we give an error, if one we then move on to running the command. We pull the command name from the grid and then add "scr_cmd_" to it, (so we can execute the script through code and so we dont have one worded named scripts).
The command scripts are where it gets fun.
We get the fill string of what the user typed and delete the part where the command name is, depending on the script we look for brackets "[ ]" (as of right now I dont know how to make it look for " with out breaking the strings), we then delete the brackets and save everything after the last ] for later (depending on the script) we are now left with what was inside the brackets being our argument for the command, and with that we configure the script to do what it does with the arguments in mind.
Commands implemented so far
Print: prints text given in [], usage: print [string to print]
Color: Changes the color of the displayed text, useage: color ID, 'Color list' for color options.
Help: Displays info about given command, usage: Help [Command to get help]
Quit: Quits the game.
I dont plan on releasing this as of right now because theres not really any fun thing to do with it.
However I have made it so you can just write your own command keyword and script for it
that being said there is a buggy earlier version I posted HERE that you can toy with if you wish.
TO DO
I started with GMWolf's user input video (check it out its awesome and helpful)
It finds what character the user has typed and compares that to an allowed keys list. (more in GMwolfs video)
I then edited it using UTF-8 character codes to replace what the player has typed to that character in a string,
using this we can now allow for more advanced things to be done.
When the user presses inter it saves what they typed in a variable which holds the input string.
As of now it runs a chain of scripts to filter what commands have been typed and matches those words to a ds_grid holding the commands we want, then sets the value of the command to true in a different grid.
Once we have done that we read the grid and check how many are true, if more then one we give an error, if none we give an error, if one we then move on to running the command. We pull the command name from the grid and then add "scr_cmd_" to it, (so we can execute the script through code and so we dont have one worded named scripts).
The command scripts are where it gets fun.
We get the fill string of what the user typed and delete the part where the command name is, depending on the script we look for brackets "[ ]" (as of right now I dont know how to make it look for " with out breaking the strings), we then delete the brackets and save everything after the last ] for later (depending on the script) we are now left with what was inside the brackets being our argument for the command, and with that we configure the script to do what it does with the arguments in mind.
Commands implemented so far
Print: prints text given in [], usage: print [string to print]
Color: Changes the color of the displayed text, useage: color ID, 'Color list' for color options.
Help: Displays info about given command, usage: Help [Command to get help]
Quit: Quits the game.
Code:
//UTF-8 FTW!! <3
special_key = ""; // making an empty var that were going to put our key into
#region //set keys ---------------------------
/* list:
(220 = \)
(219 = [ {)
(221 = ] })
(190 = .)
(191 = / ?)
(187 = = +)
(189 = - _)
(188 = ,)
(192 = ` ~) if using this as a debug system I should add an if enabled feature to this for bringing the console up or down
(96 = numpad_0)
(97 = numpad_1)
(98 = numpad_2)
(99 = numpad_3)
(100 = numpad_4)
(101 = numpad_5)
(102 = numpad_6)
(103 = numpad_7)
(104 = numpad_8)
(105 = numpad_9)
(106 = numpad_*)
(107 = numpad_+)
(109 = numpad_-)
(110 = numpad_.)
(111 = numpad_/)
(13 = numpad_enter)
(33 = pg_up)
(34 = pg_down)
(222 = " ')
*/
#endregion
#region //key id list
enum k_id{
backslash = 220,
bracksL = 219,
bracksR = 221,
ddot = 190,
foreslash = 191,
eqplus = 187,
minline = 189,
comma = 188,
tilda = 192,
np_0 = 96,
np_1 = 97,
np_2 = 98,
np_3 = 99,
np_4 = 100,
np_5 = 101,
np_6 = 102,
np_7 = 103,
np_8 = 104,
np_9 = 105,
np_star = 106,
np_plus = 107,
np_min = 109,
np_ddot = 110,
np_fslash = 111,
np_enter = 13,
pg_up = 33,
pg_down = 34,
printhes = 222,
}
#endregion
#region //If key press do this
switch(pressed_key)
{
case (k_id.backslash) : special_key = "\\"; break;
case (k_id.bracksL) : special_key = (lc_key); break;
case (k_id.bracksR) : special_key = (lc_key); break;
case (k_id.ddot) : special_key = "."; break;
case (k_id.foreslash) : special_key = (lc_key); break;
case (k_id.eqplus) : special_key = (lc_key); break;
case (k_id.minline) : special_key = (lc_key); break;
case (k_id.comma) : special_key = ","; break;
//case (k_id.tilda) : if enabled break;
case (k_id.np_0) : special_key = "0"; break;
case (k_id.np_1) : special_key = "1"; break;
case (k_id.np_2) : special_key = "2"; break;
case (k_id.np_3) : special_key = "3"; break;
case (k_id.np_4) : special_key = "4"; break;
case (k_id.np_5) : special_key = "5"; break;
case (k_id.np_6) : special_key = "6"; break;
case (k_id.np_7) : special_key = "7"; break;
case (k_id.np_8) : special_key = "8"; break;
case (k_id.np_9) : special_key = "9"; break;
case (k_id.np_star) : special_key = "*"; break;
case (k_id.np_plus) : special_key = "+"; break;
case (k_id.np_min) : special_key = "-"; break;
case (k_id.np_ddot) : special_key = "."; break;
case (k_id.np_fslash) : special_key = "/"; break;
case (k_id.np_enter) : special_key = ""; script_execute(global.consolescript); break;
case (k_id.pg_up) : break;
case (k_id.pg_down) : break;
case (k_id.printhes) : special_key = (lc_key); break;
default: special_key = "";
}
#endregion
return(special_key)
Code:
//SET UP----------------------------------------------------------------------------------------
#region//GET ARGUMENTS--------------------------------------------------------------------------
//find our arguments
#region //if just entered the word print no space
if ((global.input_string) == "print") ^^ ((global.input_string) == "PRINT") ^^ ((global.input_string) == "Print")
{
var error = string("Not enough arguments, usage: print [string to print]");
//show_message(error)
global.last_input = global.input_string;
global.input_string = error;
with(obj_input)
{
//destroy grid
ds_grid_destroy(cmd_list);
global.con_input = true;
}
var my_arguments = "";
exit;
}
#endregion
var count = string_length(value);
var instring = global.input_string;
instring = string_delete(instring,1,count+1);
var arguments = instring;
var my_arguments = string(arguments);
//find end ]
print_string_error = 0;
print_string = my_arguments;
var startbracket = 1;
var endbracket = 2;
end_pos = string_pos("]", my_arguments);
if (end_pos != 0) //if ] exists
{
//delete everything after ]
print_string = string_delete(my_arguments,(end_pos),( (string_length(my_arguments)) ));
} else {
print_string_error += endbracket;
}
start_pos = string_pos("[", my_arguments);
if (start_pos != 0) //if [ exists
{
//delete the [
print_string = string_delete(print_string,1,1);
} else {
print_string_error += startbracket;
}
#endregion
#region//SCRIPT MAIN----------------------------------------------------------------------------
var script_error = false;
//Get my arguments if there are not print the error saying so
if (my_arguments == ("")) ^^ (print_string_error == 3)
{
var error = string("Not enough arguments, usage: print [string to print]");
//show_message(error)
global.last_input = global.input_string;
global.input_string = error;
script_error = true;
}
//start backet error check
if (print_string_error == 1) && (my_arguments != (""))
{
var error = string("No starting bracket '[', usage: print [string to print]");
//show_message(error)
global.last_input = global.input_string;
global.input_string = error;
script_error = true;
}
//end backet error check
if (print_string_error == 2) && (my_arguments != (""))
{
var error = string("No ending bracket ']', usage: print [string to print]");
//show_message(error)
global.last_input = global.input_string;
global.input_string = error;
script_error = true;
}
if (script_error = false)
{
//other wise print the string
//show_message(print_string);
global.input_string = print_string;
}
#endregion
#region//CLEAN UP-------------------------------------------------------------------------------
with(obj_input)
{
//destroy grid
ds_grid_destroy(cmd_list);
global.con_input = true;
}
global.arguments_string = "";
#endregion
//FINISH----------------------------------------------------------------------------------------
exit;
I dont plan on releasing this as of right now because theres not really any fun thing to do with it.
However I have made it so you can just write your own command keyword and script for it
that being said there is a buggy earlier version I posted HERE that you can toy with if you wish.
TO DO
- Change all the chained scripts to be a single script
- implement more command ideas
- able to write and run custom system files like how .bat files work
- make ascii game from above todo
- tidy up the code and dust some debug cobwebs
Last edited: