How to use another node's variable when one only has the variable name as a string?

Godot 4.2

I want to modify a variable from one node in another node based on a text file.

In my creature node I have a variable:

var variable1 = 1

Then from another node I want to change a this variable based on a string:

#determined during runtime
var specific_variable: "variable1"
var amount: 2

func add_to_variable():
	#clearly doesn't work
	%creature.specific_variable += amount

How would I do this instead? .get() doesn’t work and I’m unable to find anything that lets me do this.

Figured it out, using set() seems to work. Though I don’t know if this is the best way of doing it.

1 Like