Invalid operands 'Array' and 'int' in operator '==' float registered as array

Godot Version

v4.1.3.stable.official

Question

I have written some code to load save data from a save file. I cannot work out why but Godot seems to think that the variable level is an array when it is a float. How can I fix this?

‘’’
extends Node

Set up variables

Array of which clues have already been found

var foundClues =
var current_room = “null”
var level = 0.0

The target save path for the save file

var save_path = “C:/Users/ezrac/OneDrive/Documents/P.I. Noire/Save Data/PISave.save”

Whether data is trying to be retrieved where it cannot be found.

var missingData = false

var axePrevious = false
var notePrevious = false
var personPrevious = false
var receiptPrevious = false

Save the game

func save():
var file = FileAccess.open(save_path, FileAccess.WRITE)
# Store the variables there
file.store_var(foundClues)
file.store_var(level)

Load a previous save

func load_data():
# If there is a save file at the save location
if FileAccess.file_exists(save_path):
var file = FileAccess.open(save_path, FileAccess.READ)
level = file.get_var(level)
if level == 1:
foundClues = file.get_var(foundClues)
if “Axe” in foundClues:
axePrevious = true
if “Note” in foundClues:
notePrevious = true
if “Person” in foundClues:
personPrevious = true
if “Receipt” in foundClues:
receiptPrevious = true
get_tree().change_scene_to_file(“res://scenes/objects/level_T.tscn”)
elif level == 1.5:
get_tree().change_scene_to_file(“res://minigame.tscn”)
else:
# Show data as missing
missingData = true

func update_clues(clue):
foundClues.insert(foundClues.size(),clue)

Clear existing save data

func clear_data():
# Write to the file
var file = FileAccess.open(save_path, FileAccess.WRITE)
# Overwrite the save data to original states
foundClues =
level = 0
# Store save data in the save file
file.store_var(foundClues)
file.store_var(level)
‘’’

first time i see a level can be a float and you check it by 1.5 of it
try specify the level variable as a float early on:

to:

var level:float = 0.0
1 Like