I just starded doing the tutorial but when i try to start the gane get an error. Why?

alex1101alex1101 Posts: 2Member

So i tryed to do the "dodge the creeps" tutorial but when i try to verify the movement i get this error:
Invalid operands 'Vector2' and 'Nil' in operator '*'.
This is the code:
extends Area2D

export (int) var SPEED
var velocity = Vector2()
var screensize

func _ready():
screensize = get_viewport_rect().size

func _process(delta):
velocity = Vector2()
if Input.is_action_pressed("ui_right"):
velocity.x += 1
if Input.is_action_pressed("ui_left"):
velocity.x -= 1
if Input.is_action_pressed("ui_down"):
velocity.y += 1
if Input.is_action_pressed("ui_up"):
velocity.y -= 1
if velocity.length() > 0:
velocity = velocity.normalized() * SPEED
$AnimatedSprite.play()
else:
$AnimatedSprite.stop()

position += velocity * delta
position.x = clamp(position.x, 0, screensize.x)
position.y = clamp(position.y, 0, screensize.y)
Tagged:

Tags :

Answers

  • TwistedTwiglegTwistedTwigleg Posts: 858Admin

    Which line is producing the error? It's hard to say for sure without knowing where to look.

    I'd say it is likely you need to assign a value to SPEED in the editor, but I'm not sure.

  • alex1101alex1101 Posts: 2Member

    Yep I'm dumb. I forgot to set the speed. Thank you!

Sign In or Register to comment.