• 2D
  • ERROR: Invalid operands 'Vector2' and 'int' in operator '+'.

I am trying to follow along with a maze tutorial for my game design class and I got this error and have no idea on how to fix it. The error : Invalid operands 'Vector2' and 'int' in operator '+'.

Here is the code I have and I think it is saying the error is on line 27.

extends Area2D

export (int) var speed

var tile_size = 64
var can_move = true
var facing = 'right'

var moves = {'right': Vector2(1, 0), 
			'left': Vector2(-1, 0), 
			'up': Vector2(0, -1), 
			'down': Vector2(0, 1)}

onready var raycasts = {'right': $RayCastRight, 
						'left': $RayCastLeft, 
						'up': $RayCastUp,
						'down': $RayCastDown}

func move(dir):
	$AnimationPlayer.playback_speed = speed
	facing = dir
	if raycasts[facing].is_colliding():
		return 
	
	can_move = false
	$AnimationPlayer.play(facing)
	$MoveTween.interpolate_property(self, "position", position, 
				position + moves[facing] + tile_size, 
				1.0 / speed, Tween.TRANS_SINE, Tween.EASE_IN_OUT)
	$MoveTween.start()
	return true

func _on_MoveTween_tween_completed(object, key):
	can_move = true 

It's also saying there is an issue with line 12 of this script:

extends "res://character/Character.gd"

signal moved
signal dead
signal grabbed_key
signal win

func _process(delta):
	if can_move:
		for dir in moves.keys():
			if Input.is_action_pressed(dir):
				if move(dir):
					emit_signal('moved')

func _on_Player_area_entered(area):
	if area.is_in_group('enemies'):
		emit_signal('dead')
	if area.has_method('pickup'):
		area.pickup()
		if area.type == 'key_red':
			emit_signal('grabbed_key')
		if area.type == 'fly':
			emit_signal('win')

Any help is appreciated I am a total noob

Hi and welcome to the forum. Your post was stuck in the queue, so please confirm your account with the email we sent so this does not happen in the future. Thanks.

On the first line you are trying to add an integer (whole number) to a Vector2, which won't work.

Maybe you meant to multiply?

position + moves[facing] * tile_size

For the second one, you have to make sure you always return the same type of value. Try changing this line to return false.

if raycasts[facing].is_colliding():
        return false

Awesome! So glad that worked. Also, be sure to confirm your account with the email we sent you so you can post freely in the future. Cheers.