Variables and constants - pantonshire/Vulcan GitHub Wiki

Variables

Variables allow you to store data. Each variable has a unique name, chosen by you, that allows you to retrieve the data that you stored in the variable.

Declaration

Making a new variable is called "declaring" it.
The syntax for declaring a variable is:

new TYPE variable called NAME = VALUE

TYPE is the type of data that you want to store in the variable, such as "integer" or "player". NAME is whatever you want to call your variable. VALUE is the variable's starting value, or what should be stored in the variable when it is created.

Assignment

Storing data in a variable is called "assigning" the variable. The syntax for assigning a value to a variable is:

set NAME to VALUE

NAME is the name of a variable that you've declared. VALUE is the data that you want to store in the variable.

Using variables

You can use a variable in place of a value. For example:

new integer variable called time = 10
tell player to burn for time seconds

will cause the player to burn for 10 seconds.

Constants

A constant is like a variable, except you cannot change its value once you've set it. The syntax for declaring a constant is very similar to declaring a variable:

new TYPE constant called NAME = VALUE

This is useful for storing things that you know will never change in value. For example, you could store pi:

new decimal constant called pi = 3.14

The following code would not compile because constants cannot have their value changed:

new decimal constant called pi = 3.14
set pi to 6.28