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.

Cheat sheet

Variables in Lua are global by default and can be accessed from anywhere in your script:

playerName = "Alex"
score = 100

These global variables can be used inside functions, loops, or anywhere else in your program.

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