Skip to content

Variables

mystborn edited this page Jun 22, 2018 · 3 revisions

In TaffyScript there are 3 types of variables: local, global, and instance.

Local

To declare a local variable, just write var and then the variable name. For example:

var name;
name = "Chris";
var age = 20;

You can declare multiple local variables on the same line by seperating each name by a comma:

var name, age;
var eye_color = "blue", hobby = "programming";
var computer_on = true, drink, dinner;

As you can see, we can mix assigning and just declaring a variable on the same line.

A local variable can only be accessed within the current scope. After the scope exits, the variable is gone forever.

Instance

When declaring instance variables, you must assign a value to the variable. Each declaration must be a seperate statement, and therefore can be seperated by semicolons or any amount of whitespace.

object obj_example {
    script create {
        name = "Chris";
        age = 20;
    }
}

These variables can only be accessed by the object instance.

Alternatively, you can also explicitly reference the instance.

object obj_example {
    script create {
        self.name = "Chris";
        self.age = 20;
    }
}

That syntax is useful if an argument corresponds with a variable name.

Global

In TaffyScript, you can access global variables by prefixing the variable name with global.. For example:

global.name = "Chris";
print(global.name);

These variables can be accessed from anywhere.

Clone this wiki locally