Need help with some code for 2d procedural animation of a spider

Godot Version

4.3

Question

`So, I’m new to using Godot, and have been trying to make a game within the engine for a couple of weeks now. I have a decent grasp on the node system, and am not too familiar with the syntax of GDScript but I know the basics, like how to make functions, make an object move and jump and other simple things like that. I started a project with the help of a tutorial, finished that prototype, started another project for another game I want to make, but then came across an interesting game jam on itch.io. It was a 1-bit game jam, and I thought, well, “this would be simple enough complete as my first jam right?” And it is pretty simple so far. I have gathered/designed some pretty simple assets to use in the game, now just waiting for the jam to start. I have a pretty definitive plan and vision for how I want the game to turn out and I guess it’s simple enough. But the thing is, my dumb brain, which clearly hasn’t got enough things to worry about right now, decided to make the enemies (I’ve only got 3 planned, may add more after the jam) move with procedural animation. I figured it was way easier than making preset animations, because I’d have to draw different animation frames. So, I looked up a tutorial for it, came across multiple, including a Miziziziz (not sure how many “iz’s” there are) tutorial, which I tested out in my project. I came across a number of issues, and managed to fix most of them, except a few. An issue pops up whenever I try to run the code. Here is the code:

@onready var joint1 = $Joint1
@onready var joint2 = $Joint1/Joint2
@onready var hand = $Joint1/Joint2/Hand
 
var len_upper = 0
var len_middle = 0
var len_lower = 0

This piece of code declares variables for the joints and markers positions and lengths

func _ready():
	len_upper = joint1.position.x
	len_middle = joint2.position.x
	len_lower = hand.position.x

And this function calls them and equates the variables to the joint position at the X-value. The error occurs in this function with the “len_upper” variable. The error states that it has an “Invalid access to property or key ‘position’ on a base object of type ‘null instance’.” Not sure exactly what this means, maybe the position statement is wrong?

If any of you guys could help me that would be great

Also, I should mention that the tutorial uses a version of Godot from 5 years ago, so this code is probably out of date (I had to change the position nodes to 2D markers). So, I might also look for a more recent tutorial.

Thanks in advance for your help.

I tried this code from tutorial and it works for me without errors:

anything you can add? like scene tree, other part of code or other nodes code

I think I fixed it; I didn’t put quotation marks around the strings, but I have run into another issue, with the rest of the code. The segments of legs are not working or moving how they are supposed to. I think I drew the sprites wrong, so I’ll try to redraw them, and import them back into the project. Thanks for your help though.

I think I fixed it; I didn’t put quotation marks around the strings, but I have run into another issue, with the rest of the code. The segments of legs are not working or moving how they are supposed to. I think I drew the sprites wrong, so I’ll try to redraw them, and import them back into the project. Thanks for your help though.