My sprite is null? I want to change it's position, but I can't interact with a null

Godot Version

4.2

Question

Hi, I’m new to Godot and programming, and I’ve been stuck on this for about a week now :frowning:

I want to change the position of card_sprite to the values in my positions array, which I am calling with the index var. I set all of positions values on _ready(): and I’m calling the _setting_position(): function on button press inside a script attached to the individual cards. Then the index number should increase, and the next card selected should move to the second item in my positions array.

I am using a unique name to access the card_sprite from inside another scene, but this sprite is returning a null error when I click the button. I don’t know how to fix this, any help would be greatly appreciated!



image
image

With slots_scene.new() you’re creating a new instance of your card_pool script. You’re not adding it to the scene tree, however, which means its _ready function (and consequently also all @onready variables) are never executed.

From what you’re describing, it sounds like what you actually want is an Autoload, though. One script that is accessible from everywhere.

Oh, wow! I had no idea about all of this, thank you for sending me this :pray:
I’ll try Autoload and update the post with results :slight_smile:

1 Like