Add information to variable

Posted by AquaBrother on Sun 15 Mar 2009 03:41 AM — 4 posts, 16,360 views.

Brazil #0
I'm trying to do a variable absorb information with a trigger... it's just like all the time someone send me a TELL MESSAGE, the variable copy the message to itself so i can see it later... the problem is, the variable can absorbe more than 1 message inside itself? i mean, if i receive like 10 TELL MESSAGENS, is there a way to put all the messagens inside the variable? Or i will have to do 10 variables?

Thx for your time xD
Australia Forum Administrator #1
Make a table. For example:


messages = messages or {}  -- create table if not exist

table.insert (messages, new_message)


That will keep adding to the messages table. Now to get them back later:


for k, v in ipairs (messages) do
  print (v)  -- print this message
end -- for

Brazil #2
thx for the information xD

i tried to do so:

if messages == {} then
print ("no msg recorded")
else
for k, v in ipairs (messages) do
print (v) -- print this message
end -- for
end


But it dont seen to be working...

rofl, i wish i was not that much noob at programing, rofl...

If you could help again, i'd appreciate it... xD
Australia Forum Administrator #3
Quote:

if messages == {} then
print ("no msg recorded")


Pretty close. In fact to test if the table is empty, do this:


if #messages == 0 then
  print ("no msg recorded")


or, for tables which might have non-numeric keys:


if next (messages) == nil then
  print ("no msg recorded")