sitestereo.blogg.se

Game maker screen wrap code command
Game maker screen wrap code command








game maker screen wrap code command
  1. Game maker screen wrap code command how to#
  2. Game maker screen wrap code command full#

Before executing the script, we must check if it really exists, by calling the script_exists() function. We use three handy GML functions: asset_get_index() returns the unique index of a game asset with a given name (passed as parameter) and we use it to get the script index that we must call. The core of the command prompt lies in the lines 11-13. Otherwise, we show the message "Unknown command." (line 15). If the script is found, we execute it (line 13).

game maker screen wrap code command

If positive, we remove the '/' symbol (line 10) and try to get an asset (script) called "Execute" (line 11).

Game maker screen wrap code command full#

This full string is split and saved in an array (line 5), with each substring separated by a blank space (we will create stringSplit function later).Īfter splitting the user input string, we check if the user is trying to call a script (the first character must be the '/' symbol, lines 6-8). The runCommand receives a string as parameter, which is the user text input (see updateTextInput, line 7). 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) 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 screen wrap code command 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. 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 screen wrap code command