23. Make the pickup safe to repeat
1. Set key_taken to false in Variable Designer for a fresh game.
2. Place the If Variable guard before Give Item and Add Score.
3. Set key_taken true as part of the successful pickup.
4. Assign the graph only to the intended pickup response.
5. Test the successful pickup. You should gain one item and five points.
6. Call it again during testing. The guard should produce the already-collected response without another reward.
Hiding the key usually prevents another ordinary click, but the flag still matters. Another script, an event, a saved room state or a later change could call the same pickup logic again.
| After a fresh run | Expected state |
|---|---|
| Before pickup | key_taken false; key quantity 0; score 0. |
| After first pickup | key_taken true; quantity 1; score 5; scene key hidden. |
| After repeated call | Same quantity and score. |
| After leaving and returning | The supported room/puzzle state remains consistent. |
For a longer asynchronous pickup sequence, consider a busy guard as well. Set busy before the first wait, reject overlapping starts and clear it on every completion path. This prevents two calls from both passing an initial test while the first is suspended.
A one-time flag and a temporary busy flag solve different problems. Keep the permanent completion flag even after adding a busy guard.
