0 votes

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


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 ;)
onready var sprite: Sprite = get_node("Sprite")#Finds child node 'sprite'


func physicsprocess(delta): #function calls 60 times a second
velocity.x = 0
if Input.isactionpressed("moveleft"):
velocity.x -=speed
if Input.is
actionpressed("moveright"):velocity.x +=speed
#pre defined variable, is just vector2 but x = 0 and y = 1
velocity = moveandslide(velocity, Vector2.UP)

**if velocity.x < 0: 
    sprite.flip_h = true
elif velocity.x > 0:
    sprite.flip_h = false**
Godot version Regular windows, code in GD script
in Engine by (47 points)

1 Answer

+1 vote
Best answer

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.

by (2,688 points)
selected by

Ah thanks, that makes sense!

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.