Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Tables are simple.
- Take your regular variable: target = "senoske"
- and when you call on "target" it'll return with "senoske".
- 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.
- table = { --table name and open the table
- ["target"] = "senoske" --key/value pair
- } --close the table
- So, now it's a table. "target" is the key and "senoske is the value".
- Normally we'd use send("kill "..target) to call "senoske" from the variable. This doesn't change much- we'd use table.target.
- 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?"
- So, it'll pull "senoske" out of table.target and viola you have a table.
- There are multiple kinds of tables. The two simplest and easiest to understand are numbered tables and libraries.
- Numbered tables have numbers for the keys, so like:
- table = { --name and open
- [1] = "lala", --key/value
- [2] = "hoho", --key/value
- [3] = "meme", --key/value
- }--make sure to always close your table.
- And libraries look like this:
- table = { --name and open
- ["target"] = "senoske" --key/value
- ["ally"] = "karai" --key/value
- ["sensefor"]= "jalo" --key/value
- }--close
- 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.
- For a numbered table you'd do table[1] or table[2].
- 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.
- For libraries you'd use:
- 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.
- for k,v in pairs(table) do <--pairs is for libraries. ipairs is for numbered tables. Think of it like "integer pairs)
- for k,v in pairs(table) do
- echo(v)
- end--for
- That would echo the library like this: "senoskekaraijalo"
- So you'd want to change the echo to:
- echo(v.." ")
- and it would turn out like this: "senoske karai jalo "
- With tables, the possibilities are endless. I hope this helps.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement