Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | AlejandroG |
Hi everyone,
I’m trying to make a simple tile-movement-based game as I’m still learning Godot. I’m trying to have the Player node call a function on an Autoload named GameGod whenever a keyboard key is pressed. I defined this function myself in the Autoload (it’s called player_moved()
).However, when the Player node calls it, the engine tells me the function doesn’t exist. Here’s the code for the Autoload:
extends Node
var PlayerScore = 0
func _ready():
pass
func player_moved():
print ("Player has moved")
$Robot1.move()
Here’s the bit of code containing the player’s Node call on the Autoload:
extends Node2D
var speed = 128
var tile_size = 32
var last_position = Vector2()
var target_position = Vector2()
var movedir = Vector2()
var is_moving_diagonally = false
onready var ray = $RayCast2D
func _ready():
position.snapped(Vector2(tile_size,tile_size))
last_position = position
target_position = position
func _input(event):
if event is InputEventKey && event.is_pressed():
GameGod.player_moved()
#(Code continues...)
This is the error I get:
Invalid call. Nonexistent function 'player_moved' in base 'Node (GameGod.gd)'.
I’m obviously doing something wrong, but I’m still coming to grips with the engine and can’t find the problem. I’d greatly appreciate any comments on this. Thanks!
HI,
have you reloaded the projekt? Autoload objects dont update on save … i believe
klaas | 2020-08-22 22:49
I tried reloading but didn’t work. However, I hadn’t thought about the fact that autoloads don’t update upon saving scenes, which is useful to know. Thanks!
AlejandroG | 2020-08-23 23:30