Change TextMesh thru GDscript

Godot Version

4.2.2

Question

All I want to do is attach a script to my meshinstance3d node containing a mesh:newtextmesh , that script will change the text instead of typing it in the properties, thus changing the text displayed. I’ve tried everything, the best I found is this: TextMesh — Godot Engine (stable) documentation in English

String text = “”

void set_text ( String value )

String get_text ( )

The text to generate mesh from.

How do I go from that to a script?

example:

extends MeshInstance3D

String text = “example”

just gives

Line 3:Unexpected “Identifier” in class body.

What’s an example script that will change the text?

Variables in GDScript are declared with the following syntax: var name = value

However, here, this isn’t what you need to do. Instead, you want to assign a property on a resource, not a node.

Assuming a TextMesh is already assigned to the MeshInstance3D’s Mesh property, you need to do the following:

extends MeshInstance3D

func _ready():
    mesh.text = "example"

Ok thanks I guess I have to learn more coding, I wanted a code example that does what I wanted and that works so I can see what that code example is and easily adapt it, seeing all that’s in it, instead of getting: Parser error: Unexpected “Identifier” in class body. and remaining in the dark after trying ```
extends MeshInstance3D

func _ready():
mesh.text = “example”

Thanks anyways.