Skip to content

Intro

In the toolbar tutorial, you might have noticed something: whenever we clicked on a button to select the tool, the player also performed the action with the current tool. This is because our controls specify that left click is the input chosen to use the current tool. However, we would like to not process any player input if we are interacting with the UI.

Preventing player input

gooey includes a handy function to check for UI interaction: ui_is_interacting(). This will return true if the player is interacting with any widget and false otherwise. We can use this directly whenever we process player input.

In this case, we can take a look at the obj_Player's state machine and see that we are checking for the corresponding Input verb1 in order to transition to the corresponding tool use. For example, to transition to the "dig" state, we are checking that the current tool is the 'dig' tool and that we have pressed any of the buttons defined in the INPUT_VERB.USE_TOOL verb:

obj_Player / Create
    self.fsm.add_transition(["idle", "walk"], "dig", function() {
        return self.tools[self.current_tool] == "dig" && InputPressed(INPUT_VERB.USE_TOOL);
    });

All we really need to do is to add a check to see whether the player is currently interacting with the UI, before processing the input:

obj_Player / Create
    self.fsm.add_transition(["idle", "walk"], "dig", function() {
        return !ui_is_interacting() && self.tools[self.current_tool] == "dig" && InputPressed(INPUT_VERB.USE_TOOL);
    });

That's all there is to it! We can do this for all places where input is processed (such as all the tool use transitions in this case).


  1. If you haven't used the Input library, you can check the documentation here. However, the same concept applies if you are working with regular Gamemaker input functions, such as keyboard_check_pressed etc.