Interactions: 106: Using a key

So far in this series on interactions, we've made a door to another scene - and then locked that door. We'll now give the player the ability to unlock it - with a keycard that must be swiped on the same Button we click to open it.

This keycard will be something that the player can carry - so it will need to be stored as an inventory item. We can define all such items in the Inventory Manager.

Click the AC Game Editor window's Inventory tab to open it, and then make sure the Items sub-tab is selected. Then click Create new item.

Doing so will reveal a large list of properties for this new item. Set its Name to Keycard, check Carry on start?, and assign an appropriate texture in its Main graphic field:

The default interface - as provided when using the New Game Wizard - has an Inventory menu that can be accessed by moving the mouse to the top of the screen:

Click an item in this menu will select it - allowing us to use it either on another item, or a Hotspot in the scene:


Some combination of settings allow for items to be selected after first choosing a Hotspot, but the above behaviour will be the case if the Settings Manager's Interaction method is set to Context Sensitive.

Let's now update our Red button Hotspot to produce a unique response when using this item on it. In the Hotspot's Inspector, click the + icon beside Inventory interactions. Set the Inventory item to Keycard, set the Player action to Walk To Marker, and create a new Interaction ActionList:

Open up the ActionList Editor for the Interaction (here, named Red button: Keycard). These Actions will be run when we use the keycard on the red button.

Set the first Action to be a Variable: Set, and set the Source to Component. As with the last tutorial, assign the door into the Variables field:

As before, the rest of the Action will set itself up to the only variable we've defined - Is locked?. Make sure that the Statement = field is set to False.

Optionally, we could also remove the keycard from the player's inventory with an Inventory: Add or remove Action:

And we're done! The player can use the keycard to unlock the door and pass through it.