-
Notifications
You must be signed in to change notification settings - Fork 1
Variables
Tom Barham edited this page Sep 14, 2015
·
1 revision
Variables allow values to be dynamically stored, changed, and outputted. MCA supports dynamically-typed variables, that is, variables do not have a preset required type.
Accessing a variable can be done by simply using the variables name. For example, the following code will output 'Hello, World!'
message = "Hello, World!";
message_length = .str_len(message);
/say The message "{message}" is {message_length} character(s) long.;
// becomes:
/say The message "Hello, World!" is 13 character(s) long.;
Variables are created, or 'declared', the first time they are set. This means that trying to use a variable before it has been set will result in a syntax error. However, variables can be set to null
if they do not need a value yet.
/say {something}; // syntax error
something = null;
/say {something};
// becomes:
/say null
Variables are only available in the block that they are defined in. As a result, variables defined inside a block cannot be accessed from outside of the block.