Advertisement
Guest User

tabletorial

a guest
Oct 16th, 2012
281
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.37 KB | None | 0 0
  1. Tables are simple.
  2.  
  3. Take your regular variable: target = "senoske"
  4. and when you call on "target" it'll return with "senoske".
  5.  
  6. Now, we can put target inside of another variable with it's current value. The variable name becomes a key, and "senoske" becomes the value of that key. The variable we put target into then becomes a table.
  7.  
  8. table = { --table name and open the table
  9. ["target"] = "senoske" --key/value pair
  10. } --close the table
  11.  
  12. So, now it's a table. "target" is the key and "senoske is the value".
  13.  
  14. Normally we'd use send("kill "..target) to call "senoske" from the variable. This doesn't change much- we'd use table.target.
  15.  
  16. so, send("kill "..table.target) would be used. The spot before the period says "Yeah, the street name we're looking for is "table". The spot after says "The house number we're looking for is "target", who owns that house?"
  17.  
  18. So, it'll pull "senoske" out of table.target and viola you have a table.
  19.  
  20.  
  21. There are multiple kinds of tables. The two simplest and easiest to understand are numbered tables and libraries.
  22.  
  23. Numbered tables have numbers for the keys, so like:
  24.  
  25. table = { --name and open
  26. [1] = "lala", --key/value
  27. [2] = "hoho", --key/value
  28. [3] = "meme", --key/value
  29. }--make sure to always close your table.
  30.  
  31. And libraries look like this:
  32.  
  33. table = { --name and open
  34. ["target"] = "senoske" --key/value
  35. ["ally"] = "karai" --key/value
  36. ["sensefor"]= "jalo" --key/value
  37. }--close
  38.  
  39.  
  40. You call all of these the same way, only the syntax is a little different. For a library, you'd do table.target or table.ally.
  41.  
  42. For a numbered table you'd do table[1] or table[2].
  43.  
  44.  
  45. If you want to loop through a table and echo its contents, you'd use FOR. There are two kinds of FOR. There is one for libraries, and one for numbered tables.
  46.  
  47. For libraries you'd use:
  48.  
  49. for k,v <--these two letters don't matter. They can be words or whatever. The easiest is to just use k for key and v for value.
  50.  
  51.  
  52. for k,v in pairs(table) do <--pairs is for libraries. ipairs is for numbered tables. Think of it like "integer pairs)
  53.  
  54.  
  55. for k,v in pairs(table) do
  56. echo(v)
  57. end--for
  58.  
  59.  
  60. That would echo the library like this: "senoskekaraijalo"
  61. So you'd want to change the echo to:
  62.  
  63. echo(v.." ")
  64.  
  65. and it would turn out like this: "senoske karai jalo "
  66.  
  67. With tables, the possibilities are endless. I hope this helps.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement