We use cookies on this site to enhance your user experience

Coding Variables

2 min

Coding Variables

The first thing to code is the placeholders for the words that the player will fill in. In a script, placeholders for information are called variables. The information they hold can be changed or replaced as needed.

Create the Variable

In Lua code, variables are created by typing local and the nameOfTheVariable. All variable names need to be one word with no spaces, like a hashtag, starting with a lowercase letter. A good variable name helps you remember what the variable is for.

Use the placeholder name you wrote down earlier as the name of your variable.

  • Under the first dashed line, type local and then a name for the variable. The placeholder in the example story was name1, so the first variable is local name1.
Original Placeholder
In a tree on a hill, lives the great wizard name1.
Placeholder in Code
while playing do
	-- Code story between the dashes	
	-- =============================================
	local name1