16. Give a GUI button a working response
For this build, use the convenience Run Visual Script behavior for a new multi-step button response. It can call a text script as well as a visual graph, and avoids the GUI catalog-action type-retention problem documented later.
func run(_context: Dictionary = {}) -> Variant:
await ChangeVariable({"name":"powered",
"operation":"set", "value":true})
await PlaySound({"assetId":"chime", "channel":"puzzle"})
await ShowMessage({"text":"The signal is on.",
"duration":2.2})
return true1. Create a GDScript record named Power the Signal, ID power_signal. Enter the code above, validate, Apply Changes and save.
2. Select Send Signal in GUI Designer, then open Events.
3. Under Click choose the convenience run-visual-script behavior. Enter power_signal in Click Target.
4. Keep Additional Event Actions empty for this complete operation. Save and test in the running game.
Figure 14. The convenience script behavior uses Click Target to identify the script.
The generic primary catalog action with a similar name is a different route. Use the convenience behavior shown here. In a fixed or pre-authored catalog action, the action fields are the inputs; the generic Target box is not their replacement.
