Nonexistent function get_pos in base "Sprite"

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

As the tittle says I am having an issue with getting sprites position from my script

I keep on getting this error

Nonexistent function get_pos in base “Sprite”

This is my code

extends Node2D

var moveSpeed = 100;

func _ready():

func _process(delta):		
	var shipPos = get_node("userShip").get_pos()
	if Input.is_action_pressed("ui_left"):
		shipPos.x = shipPos.x + moveSpeed + delta
:bust_in_silhouette: Reply From: kidscancode

get_pos() is a function that existed in Godot 2.x. If you’re following a tutorial, it’s an old one.

If you’re using Godot 3.0, the names of functions and how you access node properties has changed. The code you posted would instead look like this:

extends Node2D

var moveSpeed = 100

func _process(delta):
    if Input.is_action_pressed("ui_left"):
       get_node("userShip").position.x += moveSpeed * delta

Note at the end there: you should be multiplying by delta, not adding. Also, in Godot 3.0, the set_process(true) call is not needed.

If you’re looking for good tutorials that are up-to-date, I highly recommend starting with the official docs’ “Getting Started” section.