Horizontal flip causes execution error

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

I am very new to Godot, but I do have some prior experience with coding. I was following a very basic tutorial and the program worked fine until I tired to make my character flip upon turning round. It comes up with "Invalid set index ‘flip_h’ (on base: ‘null Instance’) with value type of ‘bool’. This, apart from the variable name, is exactly how it works in the tutorial. Anyone willing to help? Here’s the full code:

extends KinematicBody2D

#Variables
var score: int = 0 #sets coin score to null
#physics variables
var speed: int = 200
var jumpForce: int = 600
var gravity: int = 800
var velocity: Vector2 = Vector2() #pixels per second- magnitude AND direction :wink:
onready var sprite: Sprite = get_node(“Sprite”)#Finds child node ‘sprite’

warning-ignore:unused_argument

func _physics_process(delta): #function calls 60 times a second
velocity.x = 0
#condition
if Input.is_action_pressed(“move_left”):
velocity.x -=speed
if Input.is_action_pressed(“move_right”):velocity.x +=speed
#pre defined variable, is just vector2 but x = 0 and y = 1
velocity = move_and_slide(velocity, Vector2.UP)

**if velocity.x < 0: 
	sprite.flip_h = true
elif velocity.x > 0:
	sprite.flip_h = false**
:bust_in_silhouette: Reply From: Lopy

Your sprite variable seems to contain null, this is likely because get_node(“Sprite”) failed. Make sure that you haven’t renamed or moved your Node.

Ah thanks, that makes sense!

BuddyGames | 2020-12-29 16:06