Deltanic Posted May 23, 2011 Share Posted May 23, 2011 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
NeXTreme Posted May 23, 2011 Share Posted May 23, 2011 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
BriGhtx3 Posted May 23, 2011 Share Posted May 23, 2011 Or use variables. Set local queue = 0 if queue == 0 then outputChatbox("Hello") queue = 1 elseif queue == 1 outputChatBox("Hello two") queue = 2 elseif queue == 2 ... end Link to comment
Deltanic Posted May 23, 2011 Author Share Posted May 23, 2011 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
BriGhtx3 Posted May 23, 2011 Share Posted May 23, 2011 Yes it could be the worst code, becuase it is not really a queue I just wrote it very fast. If you write another 20-40 lines and a timer it could really be Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now