regarding tables in tables

Post Reply
Filion
Posts: 93
Joined: Sat Mar 26, 2011 4:21 pm

regarding tables in tables

Post by Filion »

In order to avoid polluting the namespace, I have put all my "global" variables inside wotmudmapper. I have also used function wotmudmapper:instertfunction() for the functions i have used.

Now I want to use a queue in order to "save" the movement inside there and pop every command. Though, after reading this I thought I had to use a table inside a table. So some questions have been raised.

a)If I do understand well, I can create a wotmudmapper.queue={} to start a queue.
b)How do i refer to a function for queue? Is the following enough?
Code: [show] | [select all] lua
    function wotmudmapper.queue: nameoffunction()
c)
If you use this structure in a strict queue discipline, calling only pushright and popleft, both first and last will increase continually. However, because we represent arrays in Lua with tables, you can index them either from 1 to 20 or from 16,777,216 to 16,777,236. Moreover, because Lua uses double precision to represent numbers, your program can run for two hundred years, doing one million insertions per second, before it has problems with overflows.
Does that mean that I may have to change the values of first and last, if, let's say the queue is empty?
Last edited by Filion on Sun Dec 30, 2012 3:48 pm, edited 1 time in total.

Delrayne
Posts: 159
Joined: Tue Jun 07, 2011 7:07 pm
Contact:

Re: regarding tables in tables

Post by Delrayne »

You can queue up a function the same way you would a string. As far as the table being empty, and having to change the values, just put in a simple check in your queue function to determine if something is in the queue.
Code: [show] | [select all] lua
wotmud.queue = { wotmud:nameoffunction(), "eat herb", wotmud:nameoffunction2(), "smoke pipe"}

function wotmud:queueFunction()
  if (#wotmud.queue == 0) then
    return
  elseif (wotmud.queue > 0) then
    send(wotmud.queue[1])
    table.remove(wotmud.queue, 1)
  else
    cecho("<red>[ERROR:<white> FUNCTION wotmud:queueFunction()!<red>]")
  end
end
This may not be what you are trying to do, its just what I gathered from your post. Hope this helps though.

Post Reply