Search icon
Subscription
0
Cart icon
Close icon
You have no products in your basket yet
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Lua Quick Start Guide

You're reading from  Lua Quick Start Guide

Product type Book
Published in Jul 2018
Publisher Packt
ISBN-13 9781789343229
Pages 202 pages
Edition 1st Edition
Languages
Author (1):
Gabor Szauer Gabor Szauer
Profile icon Gabor Szauer

The global table

The one thing you really need to understand about Lua is that just about everything in it is a table. Global variables in Lua (variables not declared local) live in an invisible, global table. This table is exposed as _G. This global table is just like any other table in Lua; you can perform the exact same operations on it. This section will explore two methods of working with the functionality of the global table.

Explicit variables

The loose, typed nature of variables in Lua can be great for prototyping games quickly, but it can also lead to a lot of bugs! For example, consider the following code:

five21 = 521 -- Variable name ends with a 1

for i=1,1000 do
if i == five21 then
five2l = "Five Twenty...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at £13.99/month. Cancel anytime}