Control Actions in GameMaker: Studio - dummies

Control Actions in GameMaker: Studio

By Michael Rohde

GameMaker: Studio’s Control tab (shown in this figure) includes Actions for Questions, Other, Code, and Variables. These Actions can perform complex tasks in your game.

The Control tab.
The Control tab.

Questions actions from the control tab

There are nine Questions Actions, as shown in the next figure. They ask questions such as, does something exist, is there a collision, are two values the same, and so on. And if so, the next Action in the Actions section is triggered.

Questions Actions from the control tab.
Questions Actions from the control tab.
  • Check Empty: This Action asks to see if the Instance, if placed at an indicated position, would cause a collision. This Action does require that the Instance doing the checking has a Mask index or a Sprite with a valid collision Mask.

  • Check Collision: This Action simply checks to see if the Instance collided with another Instance.

  • Check Object: This Action checks to see if there is an Instance of a specified Object at the indicated position.

  • Test Instance Count: This Action is useful if you want to test if there is a certain number of Instances in the Room, and if so, to perform the next Action.

  • Test Chance: This Action takes the result of a one-in-X chance, where you set the X (the input to test). For example, if you use 10, then there will be a 1 in 10 chance (based on a simulated dice roll) that the next Action will be triggered.

  • Check Question: This Action enables you to ask the player a yes-or-no question, which triggers a respective Action. The question appears in a pop-up window during the game.

  • Test Expression: As described in the in-software manual, this Action is the most general question action whereby you can enter an arbitrary expression and evaluate it. If the expression evaluates to true (that is, a number larger or equal to 0.5) then the next Action (or block of Actions) is performed.

  • Check Mouse: This Action returns true if the indicated mouse button is pressed and the next Action is performed; this Action is usually placed within a Step Event.

  • Check Grid: This Action returns true if the Instance is within a grid.

Other actions from the control tab

The Other Actions section of the control tab, shown in this figure, include a wide assortment of Actions associated with using code.

Other Actions from the control tab.
Other Actions from the control tab.
  • Start Block and End Block: Use these Actions to group a block of Actions, as shown in this figure. In this way, all the Actions within the block are performed if triggered.

    Normally, only the first Action that follows the question Action is triggered. Place the Start Block Action after the question being asked (in this case, a Test Variable Action). Place the End Block after the last Action you want triggered.

    Use the Start and End Block Actions to group Actions.
    Use the Start and End Block Actions to group Actions.
  • Else: Use this Action if you want something else to happen if the test question returns false instead of true. Set up your Actions so that you have the question, then a block of code to trigger if true, then an Else Action, and then another block of code to trigger if false.

  • Exit Event: Use this Action if you want no further Actions to trigger within this Event.

  • Repeat: Use this Action if you want an Action, or a block of Actions, to repeat a set number of times. This feature provides you the luxury of not having to simply paste in the same Actions over and over.

  • Call Parent Event: Use this Action with child Objects with a Parent. This is useful if you want to trigger the corresponding Event from the parent Object.

Code actions from the control tab

There are only three Code Actions, as indicated in the figure, but don’t let the limited number of options fool you — the Code Actions can be very powerful.

  • Execute Code: This Action opens up an entire world of custom code that you can write for GameMaker to execute. You can add anything from a simple, single line of code to something as complex as coding artificial intelligence.

  • Execute Script: This Action enables you to call a Script. If you intend to reuse the same block of code many times for multiple Objects, then you can write a Script, which you can then call from within an Execute Code Action.

  • Comment: This Action enables you to add a comment line to the Action list. These comments can remind you what the surrounding Actions are meant to do.

    Even though the Comment Action doesn’t necessarily do anything, besides provide you a very helpful reminder, if you place a Comment Action within, say, a Collision Event, GameMaker will still trigger the collision. That is, Collision Events are only triggered when they have an Action, which can include a Comment Action.

    Code Actions from the Control tab.
    Code Actions from the Control tab.

Variables actions from the control tab

The three Variables Actions, as shown, are

  • Set Variable: Use this Action to enter a value to a variable. If the variable does not exist, using this Action creates the variable. You can also use the Set Variable Action to configure one of GameMaker’s many global variables, as well as the built-in Instance variables.

  • Test Variable: This Action checks the value of a given variable, whether that be true, false, greater than, or lesser than, and then performs, or does not perform, the next Action based on the results.

  • Draw Variable: This Action enables you to draw the value of a variable at a position that you choose. You can only use the Draw Variable Action within a Draw Event.

    Variables Actions from the Control tab.
    Variables Actions from the Control tab.