Check one button press
TUTORIAL 05 • SCRIPT EDITOR + SCENE DESIGNER
Every chute calls the same function. It supplies one word: sheets, socks or towels. The function checks that word against the next entry on Gus’s list.
1 Leave one blank line after readout on page 13. Type this block in the same script. Start func press_bin at the left margin, lined up with func run. Click Validate, then Apply Changes and save.
func press_bin(bin_name):
if ActivePlayer() != "player" or CurrentScene() != "service_yard":
await HideGUI({"guiId": "sort_board"})
return
if IfVariable("pickup_done"):
return
var route = ["sheets", "socks", "towels"]
var step = int(Runtime.variables.get("sort_step", 0))
if bin_name != route[step]:
Runtime.variables["sort_step"] = 0
readout("Wrong chute. Start again at the first bin.")
else:
step += 1
Runtime.variables["sort_step"] = step
if step == route.size():
Runtime.variables["pickup_done"] = true
readout("Load dispatched! Gus can lock up.")
else:
readout("Accepted. Choose bin %d of 3." % (step + 1))
Runtime.state_changed()2 In Scene Designer › Service Yard › Yard sorter › Verb Actions › Use, choose Run Visual Script, then Sorter logic (sorter_logic). Apply Changes. This plain Use action runs the GDScript on page 13. The two item rules still belong under Inventory Actions.
Scene Designer • the sorter’s plain Use action calls Sorter logic.
Read one turn. At step 0, the expected word is sheets. A correct press adds 1. A wrong press puts the counter back at 0 and leaves a retry message on screen. The third correct press sets pickup_done. Further button presses leave the success message in place.
PCA 3D Adventure Studio / 14
