Topic was automatically imported from the old Question2Answer platform.
Asked By
peggels
Error parsing expression, misplaced: else
extends Area2D
export var speed = 400
var screen_size
func _ready():
screen_size = get_viewport_rect().size
func _process(delta):
var velocity = Vector2() # The player's movement vector.
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()
position += velocity * delta
position.x = clamp(position.x, 0, screen_size.x)
position.y = clamp(position.y, 0, screen_size.y)
else:
$AnimatedSprite.stop()
Your screenshot doesn’t work because apparently you linked to the file on your computer. People on the internet can’t (for obvious reasons) access your computer.
Rather than posting a screenshot, please post the text of the error message and copy and paste the script that is causing it. Note that when you post code here on this forum, there’s a “Code Sample” button just above that will ensure the code is formatted correctly.