templatesiop.blogg.se

Game maker studio 2 keyboard check
Game maker studio 2 keyboard check












game maker studio 2 keyboard check
  1. GAME MAKER STUDIO 2 KEYBOARD CHECK HOW TO
  2. GAME MAKER STUDIO 2 KEYBOARD CHECK CODE

Var scriptIndex = asset_get_index(array + "Execute") ĬommandResult = string(script_execute(scriptIndex, array)) We will create runCommand and clearUserInput in a bit.Ĭreate the clearUserInput script with the following code.Ĭreate the runCommand script with the following code, which is the core of our command prompt.Īrray = string_delete(array, 1, 1)

GAME MAKER STUDIO 2 KEYBOARD CHECK CODE

Hopefully the following code is self-explanatory by now.ĭraw_text(startX, startY, "> " + userInput) ĭraw_text(startX, startY + lineHeight, commandString) ĭraw_text(startX, startY + lineHeight * 2, commandResult) Ĭhange the updateTextInput script with the following code. This means that any input that should call a script must start with the '/' symbol and parameters are separated by blank spaces (parameters are optional and parameter count can vary based on the script/ being called).ĭeclare new variables in initTextInput to hold the command prompt result and to define each draw_text position. The command prompt will accept the following syntax: / We will focus on calling a script via this command prompt. By "simple" we mean that our command prompt will not have history and will not draw details such as a blinking cursor.

GAME MAKER STUDIO 2 KEYBOARD CHECK HOW TO

Now that we know how to get and draw user text input, let's create a simple command prompt. Modify the drawTextInput script to use the new userInput variable instead of keyboard_string.Īfter these changes, the project handles the '#' symbol and enter key (see figure below). That way, our project can draw the '#' symbol correctly. Next, we replace all '#' symbols in keyboard_string with '\#' and save the new string in the userInput variable. We included code in updateTextInput to add a line break to keyboard_string whenever the enter key is pressed, using chr(13) instead of the '#' symbol. UserInput = string_replace_all(keyboard_string, "#", "\#") This will create a new instance variable called userInput.Īdd the following code in the updateTextInput script. Assign the first one to the object's Create event and the second one to the object's Step event.Īdd the following code in the initTextInput script. For that, create two new scripts: initTextInput and updateTextInput.

game maker studio 2 keyboard check

To change that behaviour, we will need to use another variable to hold and draw the user input. Try typing the symbol and see for yourself: instead of showing #, you will get a line break. GML uses the '#' symbol to represent a new line/line break. Use the backspace key and notice that GMS takes care of deleting characters (see figure below). You should see what you type in the game screen, starting at (10, 10). clear its contents).įor this article, create a GMS project and add a room, an object, a font and, for now, a script called drawTextInput (see figure below).Īdd a Draw event in the object and call the script drawTextInput as the only Draw event action (see figure below).įinally, add one instance of the object in the room (see figure below).Īdd the following code in the drawTextInput script, changing the font resource name according to yours. Also, this variable is writable so we can manipulate it via code (e.g. GMS deletes the last character if the backspace key is pressed so you do not have to worry about that. Luckily for GMS developers, GMS provides a keyboard_string variable that holds a string containing the characters typed on the keyboard (up to 1024 characters).














Game maker studio 2 keyboard check