Tune, listen and remember the signal
SCRIPT TEXT / RADIO
Use this entire block in a separate native GDScript named radio_rules. It expects the GUI and button IDs on page 15. The radio prop opens it with no button ID. Each button then calls it with its own ID.
func run(ctx: Dictionary = {}) -> void:
var key = str(ctx.get("guiElementId", ""))
var v = Runtime.variables
var station = int(v.get("station", 0))
if key == "close_radio":
await HideGUI({"guiId":"radio"})
return
if key == "":
await ShowGUI({"guiId":"radio"})
if key == "next":
station = (station + 1) % 3
if key == "previous":
station = (station + 2) % 3
v["station"] = station
var lines = ["680 kHz", "910 kHz", "1140 kHz"]
var words = lines[station]
if key == "listen":
var reports = ["Dance music.", "Hail after dark.", "Two short rings."]
words += " " + reports[station]
if station == 2:
v["heard_signal"] = true
await ChangeGUIElementProperty({"guiId":"radio",
"elementId":"frequency", "property":"text", "value":words})The three stations are stored as 0, 1 and 2. The player sees the frequency text. The % 3 wraps around the three choices, so Next after 1140 goes back to 680. Only Listen at station 2 writes heard_signal. You can change the station names and replies while keeping this logic.
Check it in play. Choose Previous from 680. It should wrap to 1140. Tune past 1140 once without listening, then try the bell. The porter should still be at his post.
