Jump to content




[QUESTION] [LUA] Tables


  • You cannot reply to this topic
4 replies to this topic

#1 anonimo182

  • Members
  • 252 posts
  • LocationIn the universe

Posted 11 October 2012 - 02:36 AM

How could I set a variable for every file listed by this code:

list = fs.list("programs")
nfiles = #list
term.setCursorPos(1, 3)
for _,file in ipairs(list) do
print(file)
end
or give me a variable for every file and then print it?

Thanks :P/>

#2 Luanub

    Lua Nub

  • Members
  • 1,135 posts
  • LocationPortland OR

Posted 11 October 2012 - 02:39 AM

If it is stored in a table it already has a var. Here's an example on how to print them. This depends on the structure of the table however and may vary slightly.
local list = {} -- declare as table
list = fs.list("programs")

for x=1, #list do
print(list[x])
end

The first record in the table is list[1], and it increments to list[2] etc etc..

Edited by luanub, 11 October 2012 - 02:40 AM.


#3 anonimo182

  • Members
  • 252 posts
  • LocationIn the universe

Posted 11 October 2012 - 02:59 AM

but each file that is in the table can be stored as a variable, each variable for each file?

#4 PixelToast

  • Signature Abuser
  • 2,265 posts
  • Location3232235883

Posted 11 October 2012 - 03:09 AM

what you want is the global table
usage:
_G[<string>]
will get the variable of the strings name

#5 anonimo182

  • Members
  • 252 posts
  • LocationIn the universe

Posted 11 October 2012 - 02:45 PM

And how can I implement the global table?





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users