12.07.2015 Views

Wiley-World.of.Warcraft.Programming.A.Guide.and.Reference.for.Creating.WoW.Addons

Wiley-World.of.Warcraft.Programming.A.Guide.and.Reference.for.Creating.WoW.Addons

Wiley-World.of.Warcraft.Programming.A.Guide.and.Reference.for.Creating.WoW.Addons

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

CHAPTER4Working with TablesKeeping data in variables is h<strong>and</strong>y when working on simple programs, butlarger projects require an easier way to store data. Consider a simple addressbook program that enables you to electronically store contact in<strong>for</strong>mation.Using variables, that might look something like this:alice_name = “Alice Applebaum“alice_phone = “+1-212-555-1434“alice_address1 = “114 Auburn Street“alice_address2 = “Apt 14“alice_city = “Atlanta“alice_state = “GA“As you can see, using this method <strong>for</strong> more than a few simple entrieswould be unwieldy. Adding a new entry requires you to create a new variablename <strong>and</strong> enter each <strong>of</strong> the details in a new variable. Computers are all aboutautomating processes, so there has to be a better way to deal with this.Storing Data Using TablesYou may be familiar with tables or some analogous object from other programminglanguages (arrays, records, dictionaries,hashtables).InLua,tablesare objects that can be used to store other (usually related) values.To underst<strong>and</strong> how to use tables, it’s important to grasp the concept <strong>of</strong> anassociative table; which is how tables in Lua are implemented. An associativetable is a collection <strong>of</strong> values that are each associated with a key. Code can thenrequest a given key from a table <strong>and</strong> receive the value that is paired with thatkey, if such a pair exists.53

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!