Godot Version
4.1.2
Question
Why does this code not work?
var led = get_parent().get_node("LED")
var new_texture = load("res://assets/LED-2.png")
func _ready():
led.texture = new_texture
I have tried multiple methods such as using $ yet nothing happens. is there something wrong with my godot version or is it just the code?
te1ny
March 7, 2024, 11:28am
3
try change to
var new_texture = preload("res://assets/LED-2.png")
1 Like
here it is.
also I don’t get any errors it just doesn’t change the sprite.
te1ny
March 7, 2024, 11:49am
6
I don’t understand why you connect yourself to yourself via get_node, if your script already has itself, you can just delete it and refer to _ready via texture =… or self.texture. Do that, in the meantime I’ll read the documentation for you.
1 Like
te1ny
March 7, 2024, 11:52am
7
This is basically all your code that should work:
extends Sprite2D
self.texture = preload("res://assets/LED-2.png")
try deleting your code, pasting this one and running it.
1 Like
te1ny
March 7, 2024, 12:06pm
9
oh, i dont test code, sorry, try delete “self.”
extends Sprite2D
func _ready():
self.texture = preload("res://assets/LED-2.png")
it worked. I just added _ready(). thanks a lot!
1 Like
te1ny
March 7, 2024, 12:10pm
11
Sorry for the error at first, I just write in C#. good luck.
1 Like