Table Script help

Post Reply
herbert
Posts: 16
Joined: Mon May 11, 2015 4:47 pm

Table Script help

Post by herbert »

Hey I'm having issues with a table script in the game I play and its driving me, pretty nuts!

The game has things called Queueing and Separators and in each queue you're allowed to use only 9 separators

In this im using ### as the separator so,

Code: Select all

local send_string = ""

for _,command in pairs(curing.qeb) do
send_count = send_count + 1
send_string = send_string .. command .. separator

if send_count > 5 and can:act() then
send(send_string)
send_string = ""
send_count = 0
end
end

if send_string ~= "" then
send(send_string)
end

the code Im using is the above and when I add things into the curing'qeb through table.insert it sends like

outc skullcap###put skullcap in 39251###outc elm###put elm in 206382###outc valerian###put valerian
in 97943###light pipes###contemplate Konai###angel battle impatience Konai###
shield strike Konai###chasten Konai hypochondria###

Does anyone know a way I can make it only send 9 things at once?

so, it'll send nine items in the table then recheck table and resend whats left/been added since sending?

EulersIdentity
Posts: 27
Joined: Fri Jun 26, 2015 8:52 am

Re: Table Script help

Post by EulersIdentity »

I'm not totally sure I understand your code. You're pulling the commands out of curing.qeb, right?

So if curing.qeb is your queue and it's something like curing.qeb = {"outc herb1","put herb1 in pipe1","smoke pipe 1","outc herb2",...more stuff... } and you want to send "outc herb 1" first, you can do something like so:

Here's a link to it on repl.it so you can verify that it works.
Code: [show] | [select all] lua
separator = "###"
while curing.qeb[1] ~= nil do   -- repeat until queue is empty
   local send_string = table.remove(curing.qeb,1)   -- assign first item in queue to the string

   for i=2,9,1 do  -- you only want 8 more things because the first one was assigned above
      if curing.qeb[1] ~= nil then   -- ensure that something's left in the curing queue
         -- pull first item out of the queue and concatenate it onto send_string
         send_string = send_string..separator..table.remove(curing.qeb,1)
      end --if
   end --for

   send(send_string)  -- this should send 9 things if queue has 9 or more things in it
end -- while

This will pull everything out of curing.qeb and send it 9 items at a time. If you don't want to empty the contents of qeb, you can iterate of curing.qeb and just assign elements instead of using table.remove, but use a for loop like I posted to keep the strings at 9 or smaller. I think you can also do the same as I posted above by sticking everything into a function instead of a while loop and have the function call itself at the end, then just return your way out of the function once you've sent your whole queue.

Post Reply