-
Notifications
You must be signed in to change notification settings - Fork 2
Basic Types
In TaffyScript, there are very few built in types. The ones that exist are as follows:
- Number (float)
- String
- 1-Dimensional Array
- 2-Dimensional Array
- Instance
- Delegate
- Null
Number constants can be any numerical value with or without a decimal point (i.e. 13354 or 60.6). In addition, you can use the following two hex styles:
- Prefix with 0x - 0xFFFF00
- Prefix with ? - ?FFFF00
String constants can be any character in between single or double qoutes. There is no difference between the two. You can add a newline character by using \n.
In order to create an array, just assign a variable to an index like so:
array1[0] = "I'm in an array!";
array2[0, 0] = "I'm in a 2-Dimensional array!";
You can also create a 1D array in the following ways:
var arr = array_create(5)
var arr = [0, 1, 2, 3];
An array can only have two dimensions. This may change in future versions.
There is no built-in value for true and false, but there are keywords for it. The keyword true is equal to 1 and the keyword false is equal to 0. However, any numeric value that is greater than 0 evaluates to true, and vice versa for false.
A null value represents the lack of a value. Pretty similar to null in c#.
A value with the type of instance is an instance of an object. You can create an instance using the new
keyword like so:
var inst = new type_name();
A delegate is a script-like object. It can be called like a script, passed as a script argument, and be returned from scripts. To create a delegate, assign a variable to a script name:
script test {
print("hello");
}
script main {
var delegate = test;
delegate();
}
You can create a delegate from an instance script as well:
object obj_test {
script test {
print("hello");
}
}
script main {
var obj = new obj_test();
var delegate = obj.test;
delegate();
}
You can also create delegates from lambdas:
script main {
var delegate = script { print("hello"); }
delegate();
}