Jump to content

Table FTW??


Piorun

Recommended Posts

I have a question - why this code doesn't works?

  
newTable =  
{ 
"1st value", 
"2nd value" 
} 
  
addCommandHandler("showmetable", getRootElement(), 
function() 
   for i,v in ipairs(newTable) do 
      outputChatBox(tostring(newTable[i])) 
   end 
end) 
  

???

Link to comment

show the error.

EDIT:

i think this is correct:

  
  
      
    newTable = 
    { 
    "1st value", 
    "2nd value" 
    } 
      
    addCommandHandler("showmetable", getRootElement(), 
    function() 
       for i,v in ipairs(newTable) do 
          outputChatBox(tostring(v)) 
       end 
    end) 
      

Link to comment

i tested the code here (with a little edition):

http://www.lua.org/cgi-bin/demo

and it works fine:

newTable = 
{ 
 "1st value", 
 "2nd value" 
 } 
  -- loop from your code works fine (print instead of outputChatBox to run it in demo) 
   for i,v in ipairs(newTable) do 
     print(tostring(newTable[i])) 
   end 
--this also works, I think its better  
   for i,v in ipairs(newTable) do 
     print(v) 
   end 

Link to comment
  
newTable = 
{ 
"1st value", 
"2nd value" 
} 
  
addCommandHandler("showmetable", getRootElement(), 
function() 
   for i,v in ipairs(newTable) do 
      outputChatBox(v) 
   end 
end) 
  

I edited my code and i still have an error. Bad argument in outputChatBox

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...