Skip to reading
GDScript Programming & Godot

52. Expose a native function as a visual node

Edition 0.86.4.1 HF1

0.86.4.1 Hotfix 1 edition. Earlier lessons and screenshots retain their original version context; revised references and supplements describe the newer behavior.

Download PDFView illustrations
Code example
func award(points: int, message: String = "Well done.") -> int:
    var updated: int = int(Variable.score.value) + points
    Variable.score.value = updated
    Log(message)
    return updated

1. Create a native script reward_gd with this function. Validate and Apply Changes.

2. Open Functions as Nodes. Add a function definition named award and a useful display name.

3. Add points as int, then message as string, in the same order as the source. Enter defaults that match those types. Check Expose as Action and Visual Node.

4. Click Use Definitions to accept the metadata, then Apply Changes to save the script.

5. In a visual script or supported action list, add Call Script Function, choose the published function, fill in the parameters and optionally select a result variable.

Figure 17. The exposed function definition describes the source function’s parameter contract.

Page 61 of 378Permalink
Go to page