That’s interesting. However why not just use a variant return?
func get_rect_or_null(position: Vector2, size: Vector2) -> variant:
if is_error_for_some_reason:
return false
else:
return Rect2(position, size)
I also personally am uncomfortable using things like Vector2.ZERO to indicate an error. For instance a position of that vector2 is perfectly valid, and so is a size. At least with a set_cell and cell_atlas, it makes sense that a cell_atlas cannot be negative, so (-1, -1) unsets it, but personally I still don’t like it (and of course we have the simpler erase_cell.)
But it is also a bit of a pain to interpret a return dictionary for success or error messages etc. Seems too clunky to me, with the use of magic strings.
It is a shame you cant do something like:
func do_something() -> null or Rect2
Like just literally a minute ago I ran into this problem, my queue class:
func get_next_action_in_queue() -> Vector2i:
return Queue.pop_front()
I really wanted to do this but you can’t.
func get_next_action_in_queue() -> Vector2i:
if Queue.is_empty():
return false
return Queue.pop_front()
And I did not want to return a dictionary nor a variant. So now I just have to make sure that before trying to get the next item in the queue I have to check it is not empty.
if not ChunkGenerationQueue.is_queue_empty():
_generate_chunk(ChunkGenerationQueue.get_next_action_in_queue())
Which is still neater than returning a dictionary, and more typesafe than returning a variant, but I wish I could enforce it a bit more just in case I forget in the future! It seems vunerable at the moment.
I could throw an error I suppose if you try to get a task from the queue if the queue is empty. Hmm, that is probably not a bad idea. What do you think?