Welcome to the Achaea Forums! Please be sure to read the Forum Rules.

[Lua]Table-torial

JonathinJonathin Grand Rapids, MIMember Posts: 3,324 @@ - Legendary Achaean
edited October 2012 in Client Help
So I was talking with Senoske about Lua earlier and he mentioned that he didn't understand tables. I wrote him up a little tutorial on tables in Lua. It's far, very far from comprehensive, but it should be able to get some people started. The tabletorial is located on pastebin.


It's unlisted and shouldn't ever expire. I hope it helps at least someone with their table-woes.

My site will remain up, but will not be maintained. The repository will continue to have scripts added to it if I decide to play another game. Maybe I'll see you around in Starmourn!
Tutorials and scripts  The Repository

Vayne

Comments

  • AntoniusAntonius Member Posts: 4,969 @@ - Legendary Achaean
    Out of curiosity, is there a reason you wrap your keys in square brackets?
  • JonathinJonathin Grand Rapids, MIMember Posts: 3,324 @@ - Legendary Achaean
    edited October 2012
    Habit and consistency, I guess. If there's some major significance to it, I'm not sure. I learned how to use tables by myself, so I didn't learn things that people would've learned by being taught by a professional.


    ETA: I just posted this tutorial on my website. Should be easy enough to find.
    Post edited by Jonathin on

    My site will remain up, but will not be maintained. The repository will continue to have scripts added to it if I decide to play another game. Maybe I'll see you around in Starmourn!
    Tutorials and scripts  The Repository

  • EldEld Member Posts: 3,946 @@ - Legendary Achaean
    The bracket format is the most general way to write the keys for Lua tables. Other forms, such as omitting the keys entirely in numbered lists, or just using key=value for one-word string keys, are basically just shorthand. It's a little clunky, but it using it consistently points out the fact that all tables are still the same data type, regardless of the type of key used. And you'll need them if you want to use keys that include spaces or punctiation, like myTable={['first item'] = 'one', ['second item'] = 'two',...}.
    Jonathin
  • IocunIocun Member Posts: 3,543 @@ - Legendary Achaean
    Or key names that are reserved Lua terms like "not", "for", "function", etc.
    JonathinEld
  • EldEld Member Posts: 3,946 @@ - Legendary Achaean
    Just now got around to actually reading through the tutorial. Nice little intro, but a couple quibbles. It would be preferable, on principle, to name your example table something other than "table", since if you actually make a variable called table, you'll overwrite the builtin one and lose access to all your standard table functions (table.size, table.insert, and so on). And your "library" example (the table with string keys) is missing commas.
  • JonathinJonathin Grand Rapids, MIMember Posts: 3,324 @@ - Legendary Achaean
    My bad. I'll fix it up on my site (since I can't edit pastebin) in a bit.

    My site will remain up, but will not be maintained. The repository will continue to have scripts added to it if I decide to play another game. Maybe I'll see you around in Starmourn!
    Tutorials and scripts  The Repository

Sign In to Comment.