Is there any workaround to pass a reference to a node property instead of a value?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By AlwaysDan

I am trying to create a function that will change a value temporarily, but I can’t figure out if there’s a way to do it. Here’s what I have

func setTemp(prop,tempVal,time):
	var origVal = prop
	prop = tempVal
	await get_tree().create_timer(time).timeout
	prop = origVal

setTemp(scale.x,0.5,0.3)

So I’d like this to set the x scale of the node to .5 for .3 seconds, before returning to the original value. Is there an alternate way I can write this? Thanks.

:bust_in_silhouette: Reply From: LeslieS

The reason why it is not working is that you are not passing in an actual node property.
You are just passing in the integer x value of the scale.
You are going to have to change the function to accept the node and gain access to its scale property.

func setTemp(myNode, tempVal,Time): 
    var origVal = myNode.scale.x
    myNode.scale.x = tempVal
    await get_tree().create_timer(time).timeout
    myNode.scale.x = origVal

setTemp(my_node,0.5,0.3)

Thanks for your response! I’m looking for a way to make it as reusable as possible for more than just the scale property, so I tried passing in the property to be changed as a string, and this worked for me:

func setTemp(myNode,propString,tempVal,time):
			var origVal = myNode.get(propString)
			myNode.set(propString,tempVal)
			await get_tree().create_timer(time).timeout
			myNode.set(propString,origVal)

AlwaysDan | 2022-12-27 19:14