Menu
CoddyTech

Global Variables

Part of the Fundamentals section of Coddy's Lua journey. Lesson 83 of 90.

In Lua, a variable you create without the local keyword is a global variable by default. This means the variable can be accessed and used from anywhere in your script.

Here's how you create a global variable:

playerName = "Alex"
score = 100

Both playerName and score are global variables because they were declared without the local keyword. Once created, these variables can be accessed from any part of your program - inside functions, loops, or anywhere else in your script. Because any part of the program can change a global, most Lua code makes a variable local unless it really needs to be shared, as the next lessons show.

Try it yourself

This lesson doesn't include a code challenge.

quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Fundamentals

Practice on your own: Online Lua compiler