I am new to godot and I'm trying to create a platformer but i can't figure out how to work with properties.

I have this Light2d node as a child of my player node:

and i have this node called sanity which the player can pick:

I wanted to increase the scale of the Light2d node(texture_scale) when the player picks up the sanity object.

I tried using get() and set() functions but i can't seem to get it right.

How do i access light2d's texture_scale property inside the sanity node's script?

You could try something like this in your sanity script, assuming the player node is always called Player and it always has a child node called Light2D:

extends Area2D
func _on_sanity_body_entered(body):
	if (body.name == "Player"):
		body.get_node("Light2D").texture_scale + = 1
		queue_free()

Though, what I would recommend doing is adding a function to your player script and having the sanity object call that. Something like this:

Player script

func perform_sanity_pickup():
	get_node("Light2D").texture_scale += 1
	print ("Player got some sanity")

Then on the sanity script:

extends Area2D
func _on_sanity_body_entered(body):
	if (body.has_method("perform_sanity_pickup"):
		body.perform_sanity_pickup()
		queue_free()

That way, you can change the layout of the player and just update perform_sanity_pickup, the player node doesn't have to be called Player exactly for the pickup to work, and if you later decide to give something else the ability to pickup sanity it only needs to implement perform_sanity_pickup and it should work.

@TwistedTwigleg Thanks!! i implemented it and it works perfectly! I learned about tweens yesterday, so i used a tween to smooth out the transition! check it out! -

2 years later