Expect ',' or ')'

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

Just trying to continue a 2d isometric game from Godot 2 to 3. Have an issue with character controller, ‘func _input(event):’ related.
Here’s the script:

extends KinematicBody2D

# movement related variables and constants
var vel
var moveDir

# direction constants
var DIR_LEFT = Vector2(-64, -32).normalized()
var DIR_RIGHT = Vector2(64, 32).normalized()
var DIR_UP = Vector2(64, -32).normalized()
var DIR_DOWN = Vector2(-64, 32).normalized()
var DIR_ZERO = Vector2(0, 0)

const MAX_SPEED = 1.30
const MOVE_FORCE = 30.0
const GRID = 20

var animSprite
var animPlayer

func _ready():
	# initializing params
	vel = DIR_ZERO
	moveDir = DIR_ZERO
	animSprite = get_node("animSprite")
	animPlayer = get_node("animPlayer")
	# enabling process

func _physics_process(delta):
	# calculate velocity
	var deltaV = moveDir * MOVE_FORCE * delta
	if vel.length() + deltaV.length() <= MAX_SPEED:
		vel += deltaV
	else: # cap  max velocity
		vel = moveDir * MAX_SPEED
	# move the char if dir is non-zero
	if moveDir != DIR_ZERO:

# process button press from player
func _input(event):
	# controls for PC
	if event is InputEventKey:
		# deciding the direction of movement and setting animation
		if event.is_action_pressed("down_move") && !event.is_echo():
			moveDir = DIR_DOWN
		if event.is_action_pressed("up_move") && !event.is_echo():
			moveDir = DIR_UP
		if event.is_action_pressed("left_move") && !event.is_echo():
			moveDir = DIR_LEFT
		if event.is_action_pressed("right_move") && !event.is_echo():
			moveDir = DIR_RIGHT
		# set moveDir as zero upon release and pause the animation
		else (event.is_action_released("down_move") && moveDir == DIR_DOWN)
			|| (event.is_action_released("up_move") && moveDir == DIR_UP)
			|| (event.is_action_released("left_move") && moveDir == DIR_LEFT)
			|| (event.is_action_released("right_move")&& moveDir == DIR_RIGHT):
					moveDir = DIR_ZERO
					# pause the animation
	#controls for touch devices — to be expanded later
	if event.type == InputEvent.SCREEN_TOUCH:
		moveDir = DIR_RIGHT

Are you saying that somewhere in this script you have an error? Can you indicate what line?

kidscancode | 2020-01-05 19:02

It says at ‘func _input(event):’ line.
But i guess error comes from inside that function.

jymis | 2020-01-05 19:09

:bust_in_silhouette: Reply From: kidscancode

The line before the error is the cause:


Unbalanced parentheses.


But now i have an error at that line:
‘else (event.is_action_released(“down_move”) && moveDir == DIR_DOWN)’
expecting ‘:’ at the end of the line

There is a ‘:’ but with several ‘||’ operators between, maybe that’s the problem, but i don’t know how to correct it.

jymis | 2020-01-05 19:17

An else line can’t contain anything else, it’s just else:

Maybe you meant elif ? I don’t know, that code seems a mess.

kidscancode | 2020-01-05 19:21

It was ‘if’ at first, I’ve put it back instead of ‘else’ right now,
but i get the same error.

Maybe that part with all action_released stuff should be outside of that function ?

Sry, I’m not a dev, but an artist trying to move an old project to Godot 3

jymis | 2020-01-05 19:28

Ok i’ve fixed it.

All ‘[direction]move’ were the old InputMap. It’s 'ui[direction]’ now.

Plus, I’ve breaked the ‘is_action_released’ part down into four ‘if’.

Thank you :slight_smile:

jymis | 2020-01-05 19:43