mirror of
https://github.com/krgamestudios/Toy.git
synced 2026-04-15 14:54:07 +10:00
76 lines
1.1 KiB
Plaintext
76 lines
1.1 KiB
Plaintext
//declare a variable with an initial value
|
|
var answer = 42;
|
|
|
|
//declare a variable without an initial value
|
|
var empty;
|
|
|
|
//assign a previously existing variable
|
|
answer = 6 * 9;
|
|
|
|
//access a variable
|
|
answer = answer + 1;
|
|
|
|
//compound assignments
|
|
answer += 5;
|
|
answer -= 5;
|
|
answer *= 9;
|
|
answer /= 2;
|
|
answer %= 10;
|
|
|
|
//equality checks
|
|
print 1 == 1; //true
|
|
print 1 != 1; //false
|
|
|
|
//comparison checks
|
|
print 1 < 2; //true
|
|
|
|
print "foo" > "bar"; //true
|
|
|
|
print 1 < 2; //true
|
|
print 1 > 2; //false
|
|
|
|
print 2 <= 2; //true
|
|
print 2 >= 2; //true
|
|
|
|
print 1 <= 2; //true
|
|
print 1 >= 2; //false
|
|
|
|
//logical checks
|
|
print true && true; //true
|
|
print true && false; //false
|
|
print false && true; //false
|
|
print false && false; //false
|
|
|
|
print true || true; //true
|
|
print true || false; //true
|
|
print false || true; //true
|
|
print false || false; //false
|
|
|
|
print !true; //false
|
|
print !false; //true
|
|
|
|
//precedence
|
|
print true && false || true; //URGENT: a grouping warning is needed for this, see issue #154
|
|
|
|
//types
|
|
var a: int;
|
|
var b: int = 42;
|
|
|
|
a = 69;
|
|
b = 8891;
|
|
|
|
print a;
|
|
print b;
|
|
|
|
//constants
|
|
var c: int const = 42;
|
|
|
|
print c;
|
|
|
|
//indexing
|
|
var s = "Hello" .. "world!";
|
|
|
|
print s[3, 3];
|
|
|
|
//TODO: type casting
|