Invalid operands 'bool' and 'int' in operator '=='. Trying to set up a FSM

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

Hi Folks,
I’m fairly new to Godot Engine and to programing in general (although I’ve worked with the RPG Maker in the distant past and thus have a basic understanding of what is going on).
Right now I’m trying to set up a small platformer and while it get’s more complicated I wanted to implement a FSM. I found all tutorials how to set it up in Godot fairly complicated with lots of code etc. So I thought I can just do it with a simple variable that has different names that are being switched. (More or less like in Game Maker where this was really easy and worked fine).
It all worked just (nearly) as intended until now. I wanted to implement a “Jump” state but when switching to the state it gets the following error massage:

Invalid operands ‘bool’ and ‘int’ in operator ‘==’.

I’ve done the same with all states I made before. I cannot add a jump state, but the previous are all working.
I hope you can help me. If you find other errors or an easier way to do it, I’m grateful for any advice. :slight_smile:

I also found no easy way to switch to another state if an animation has ended so I just did sort of a timer, which I also found complicated with the operator “timer”, so I did it with a variable that counts up.

Here is the code:

extends KinematicBody2D

const UP = Vector2(0, -1)
const GRAVITY = 20
const ACCEL = 15
const MAXSPEEDWALK = 100
const MAXSPEEDRUN = 200
const JUMP = 600
var motion = Vector2()
var fall = false
var jump = false
var hitground = false
var wait = 0

enum states {
	idle,
	walk,
	startrun,
	endrun,
	run,
	jump,
	fall,
	hitground,
}

var states = idle

func _physics_process(delta):

motion.y += GRAVITY
var friction = false

# IDLE STATE------------------------------------------------------------------
if states == idle:

	if Input.is_action_pressed("ui_right") and not Input.is_action_pressed("ui_left"):
		if Input.is_action_pressed("ui_cancel"):
			$Sprite.flip_h = true
			states = startrun
		else: 
			states = walk
	
	elif Input.is_action_pressed("ui_left") and not Input.is_action_pressed("ui_right"):
		if Input.is_action_pressed("ui_cancel"):
			$Sprite.flip_h = false
			states = startrun
		else: 
			states = walk
	elif Input.is_action_just_pressed("ui_select"):
		states = jump
		
	else:
		friction = true
		$Sprite.play("idle")
	
# WALK STATE ------------------------------------------------------------------
elif states == walk:
	
	if Input.is_action_pressed("ui_right") and not Input.is_action_pressed("ui_left"):
		if Input.is_action_pressed("ui_cancel"):
			states = startrun
		else:
			motion.x = min(motion.x+ACCEL, MAXSPEEDWALK)
			$Sprite.flip_h = true
			$Sprite.play("walk")
			motion = move_and_slide(motion, UP)
	
	elif Input.is_action_pressed("ui_left") and not Input.is_action_pressed("ui_right"):
		if Input.is_action_pressed("ui_cancel"):
			states = startrun
		else:
			motion.x = max(motion.x-ACCEL, -MAXSPEEDWALK)
			$Sprite.flip_h = false
			$Sprite.play("walk")
			motion = move_and_slide(motion, UP)
	else:
		states = idle
	
# START RUN -----------------------------------------------------------------
elif states == startrun:
	$Sprite.play("startrun")
	if Input.is_action_pressed("ui_right") and not Input.is_action_pressed("ui_left"):
		$Sprite.flip_h = true
		motion.x = min(motion.x+ACCEL, MAXSPEEDWALK)
	elif Input.is_action_pressed("ui_left") and not Input.is_action_pressed("ui_right"):
		$Sprite.flip_h = false
		motion.x = max(motion.x-ACCEL, -MAXSPEEDWALK)
	motion = move_and_slide(motion, UP)
	
	wait = min(wait+1, 12)
	if wait == 12:
		wait = 0
		states = run
	
# END RUN --------------------------------------------------------------------
elif states == endrun:
	$Sprite.play("endrun")
	
	motion.x = lerp(motion.x, 0, 0.1)
	motion = move_and_slide(motion, UP)
	wait = min(wait+1, 45)
	if wait == 45:
		wait = 0
		states = walk

# RUN STATE ---------------------------------------------------------------
elif states == run:
	
	if Input.is_action_pressed("ui_right") and not Input.is_action_pressed("ui_left"):
		if Input.is_action_pressed("ui_cancel"):
			
			motion.x = min(motion.x+ACCEL, MAXSPEEDRUN)
			$Sprite.flip_h = true
			$Sprite.play("run")
			motion = move_and_slide(motion, UP)
			
			
		else:
			states = endrun
			
	
	elif Input.is_action_pressed("ui_left") and not Input.is_action_pressed("ui_right"):
		if Input.is_action_pressed("ui_cancel"):
			
			motion.x = max(motion.x-ACCEL, -MAXSPEEDRUN)
			$Sprite.flip_h = false
			$Sprite.play("run")
			motion = move_and_slide(motion, UP)
		else: states = endrun
			
	else:
		states = endrun
	
# JUMP ----------------------------------------------------------------------
elif states == jump:
	pass

elif states == fall:
	pass

elif states == hitground:
	pass
:bust_in_silhouette: Reply From: kidscancode
var jump = false

enum states {
    idle,
    walk,
    startrun,
    endrun,
    run,
    jump,
    fall,
    hitground,
}

You’ve reused the name jump.

Oh wow, it’s that simple. Feeling kinda dumb now… thanks!
I just could not figure out what the error message means, some stuff is still kinda cryptic to me.

Ypso | 2018-09-11 13:27