Can anyone help with the implementation of the queue in Godot 4?

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

I need to implement a queue for my game “tower defense” genre, and I want to do it with the queue, but apparently in godot engine 4 just does not exist “queue”, because I could not find information about it

Isn’t an array already a queue, if you use pop_front() and push_back()?

SteveSmith | 2023-01-02 14:38

:bust_in_silhouette: Reply From: SQBX

You can do somethin’ like this:

var queue = []
var max_queue_size = 10

# Add an item to the queue if it has not reached its maximum capacity
func add_to_queue(item):
    if len(queue) < max_queue_size:

# Removes the front item from the queue and returns whether or not the queue was empty
func finish_queue_front():
    return bool(queue.pop_front())

Oh yeah, that might work, thanks for the help)

InkRobert | 2023-01-02 16:57

You’re welcome!

SQBX | 2023-01-02 17:54