Maybe if the code is rephrased a little, it would be easier to understand:
//Step event
//Copy out the first three characters from the keyboard input buffer to look at
var input;
input = string_copy(keyboard_string, 1, 3);
//Check it against "pyo"
if (input == "pyo") {
//Do something...
keyboard_string = ""; //Clear the input so that further characters can be typed
}
I don't understand the majority of this script. What does the "i" stand for? What do you mean //do whatever? Do you mean I can put that wherever. How does this code detect that the player is typing?
1. In the context of Arkaic.ind's code, the
i is known as an
iteration variable. Simply put, it counts the number of times that a loop (a repeating statement, in this case a
for loop) has run. Without it, the loop simply doesn't know when enough is enough, and when that happens, we refer to it as an
infinite loop.
2. // (and similarly /* */ for the equivalent that spans multiple lines) are known as
comments. They are text inserted into code that only serve as human-readable instructions or clues (i.e. the runner won't care about them, just you and I). The first comment is telling you to put the code in the step event, and the comment that reads "do something" is telling you to substitute the comment with code that you want to run at that point.
3. keyboard_string is a built-in variable that keeps track of the last 1024 letters, numbers and symbols that the player has typed through the keyboard. By extracting characters off it as shown, we can see what the user has typed and perform actions according to what is there. Functionalities like these can be looked up in the manual (press F1 in GM) in case you run across an unfamiliar one.
GameGeisha