Menu
Coddy logo textTech

Global Variables

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

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.

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