How can global_position not be identified in the current scope?

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

I have a simple testing script which allows me to move a node around based on different inputs from my keyboard which I can change per node (think WASD and IJKL). Ever since I updated to 3.3 I’ve been getting an error. Sometimes I’ll make changes to a script like this that inherits from Node, and all of a sudden I’ll get an error:

“The identifier global_position isn’t declared in the current scope”

Now this same script had been working before, so I’m not sure if I changed something I’m not aware of. Here’s my code:

extends Node

export var speed : float = 1
export(String, "Motor 1", "Motor 2") var motor = "Motor 1"

func _process(delta):
var movedirection
if motor == "Motor 1":
	movedirection = testdir.direction_from_input_test1()
elif motor == "Motor 2":
	movedirection = testdir.direction_from_input_test2()
global_position = global_position + (movedirection * speed)

Does anyone have any ideas? I’m guessing I’m misunderstanding the intended use of something. Thanks very much for your time.

Edit: I should mention closing and re-opening the editor doesn’t fix it.

:bust_in_silhouette: Reply From: timothybrentwood
extends Node

Node objects don’t have a global_position. Your object needs to inherit from a Node2D object (or lower) to have a global_position.

Oops. Thank you for taking the time to respond. I appreciate it.

rainswell | 2021-07-09 18:25