So I’m running into an issue while implementing an ‘undo’ mechanic in Godot Engine v4.4.1 using GDScript. I’m trying to limit the size of the undo queue, and cut off the end once it exceeds the limit.
The code snippet looks as such, where Command is a custom class, and executed commands get instantiated as nodes in the tree (hence the queue_free()):
const QUEUE_LIMIT: int = 5
var undo_queue: Array[ Command ] = []
if undo_queue.size() > QUEUE_LIMIT:
print("too big")
undo_queue.pop_back().queue_free()
The issue is that the if statement never triggers.
If I run the following:
print(type_string(typeof(undo_queue.size())))
and
print(type_string(typeof(QUEUE_LIMIT)))
both correctly print ‘int’. However, if I run this:
print(type_string(typeof(undo_queue.size()>QUEUE_LIMIT)))
it prints ‘Object’, when the operation should be giving me a boolean.
In fact, even this:
var testvar: int = 1
var testvar2: int = 2
print(type_string(typeof(testvar2>testvar)))
prints ‘Object’, while this:
print(type_string(typeof(2>1)))
fortunately prints ‘bool’.
Does anyone know what’s going on and how to get around it? Assigning the comparison to a variable in advance doesn’t seem to work either. Thanks in advance.
boolfor me: gdscript-online.github.io/…