Jump to content

How to make a queue?


Recommended Posts

Since I'm making a script that definitely needs a queue, I need a way to do it. My idea is to output messages with onClientRender and some DX functions, but only one can be shown at a time. So if there's another message called, it has to wait till the previous message has been gone.

One waiting message isn't a problem yet, but the real problem for me occurs when you know that the queue can be even 5 messages that have to wait.

So, does anyone know a fine script for this?

Link to comment

Use a table to queue messages, then retrieve them one by one.

  
messages = {} 
messages[1] = "Hey, this is the first message" 
messages[2] = "This is teh 2nd msg" 
  
  
outputChatBox(messages[1])  -- Would write in chatbox:  
-- [i]Hey, this is the first message[/i] 
  

Link to comment
local queue = 0 
if queue == 0 then 
queue = 1 
elseif queue == 1 
queue = 2 
elseif queue == 2 
... 
end 
  

That's the worst code possible. Better use this instead, since this one can have a queue infinetly long without having more script, and it calls itself after it's finished.. But this opened my eyes though, I can surely use it in my script :)

  
local msg = {} 
local curMsg = 0 
local acceptNew = true -- This could even be removed, just don't have the desire to do it  
  
-- on event/other function: 
msg[#msg+1] = "text" 
output ( ) end 
  
-- the function 
function output ( ) 
    if acceptNew then 
        acceptNew = false 
        outputChatBox ( msg[curMsg] ) 
        setTimer ( function ( )  
            if not curMsg == #msg then curMsg = curMsg + 1  
            output ( )  
            else acceptNew = true end, 
            1000, 1 ) 
    end 
end 
  

@NeXTreme: That's just a normal table? eeh?

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...