Detecting When The Puzzle Is Solved
By completing this step in the Tagged Lights Puzzle tutorial, you'll learn how to detect when the player solves the puzzle so you can spawn an item and prevent further interaction with the puzzle
Detecting a Solved Puzzle
This section shows how to detect when the player solves the puzzle by finding the right combination of lights. When the puzzle is solved, the Item Spawner device should be enabled so that it can spawn its item.
Follow these steps to detect when the player solves the puzzle:
- Add an editable
item_spawner_devicefield namedItemSpawnerto thetagged_lights_puzzleclass, to represent the Item Spawner device.@editable ItemSpawner : item_spawner_device = item_spawner_device{} - Next, define what state the lights should be in to solve the puzzle. Since the representation of the lights’ state is a
logicarray, the solved state of the lights should also be alogicarray to easily compare the two. Create an editablelogicarray field namedSolvedLightsStateto thetagged_lights_puzzleclass. In this example, the player must turn on all the lights to solve the puzzle, so initialize each element with the valuetrueto represent the light being on.@editable SolvedLightsState : []logic = array{true, true, true, true} - Save the file in Visual Studio Code.
- In the UEFN toolbar, click Build Verse Scripts to update your Verse device in the level.
- In the Outliner, select the tagged_lights_puzzle to open its Details panel.
- In the Details panel, set the Item Spawner property to the Item Spawner device that’s in the level.
- Next, develop the code that checks if the current
LightsStatematches theSolvedLightsState. Add a new method namedIsPuzzleSolved()to thetagged_lights_puzzleclass. This method should succeed if the puzzle is solved and fail if it’s not, to let its caller know the result of the check. This means the method should be marked as failable with thedecidesspecifier. Since the method has thedecidesspecifier, it must also have thetransactsspecifier, which means the actions performed by this method can be rolled back (as if the actions were never performed), if there’s a failure anywhere in the method.
You're reading a preview
The full reference is free for BrainDeadGuild Discord members — sign in to read it all, or open the original at the source.
Sign in with your BrainDead.TV / BrainDeadGuild Discord account for full access.