-
Notifications
You must be signed in to change notification settings - Fork 0
Language Features
Cuber01 edited this page Oct 7, 2025
·
4 revisions
Supported operators: +, -, *, :
1 + 1; // 2
"str" + "ing"; // string
1 - 1; // 0
2 * 4; // 8
4 / 2; // 2Supported operators: ||, &&
true || false; // true
true && false; // false-1; // -1
!true; // false// Numbers
1;
2.3;
// True and false
true;
false;
// Strings
"Hello World!"(2 + 2) * 4; // 161 == 1 ? true : false; // If 1 == 1 then true else false (Expected: true) Variables can hold value of any of the following types:
- number (double)
- string
- boolean
- null
- instance
- function/method
- class
var a; // null
var b = 1; // 1
var a = 3; // Error: Redefining is illegal
b = 4;Function can return any valid value via the return statement. If unspecified or there's no return, they return null.
function betterPrint(text)
{
print(text);
}
betterPrint("Hello World!");
function nothing()
{
}
function nothingButBetter()
{
return null;
}
function something()
{
return true;
}
var a = nothing(); // null
a = nothingButBetter(); // null
a = something(); // trueif(true)
{
print("Truth!");
}
else if (false)
{
print("Unreachable");
}var i = 10;
while(i > 0)
{
print(i);
i--;
}
for (var i = 1; i < 100; i++)
{
print(i);
}while(true)
{
}
for(;;)
{
}while(true)
{
continue;
print("Unreachable.");
}while(true)
{
break;
}
print("Reachable.");var a = 5;
a++; // 6
a += 2; // 8
a -= 3; // 5
a *= 2; // 10
a /= 2; // 5
a--; // 4var a = [0, 1, 2];
a[0] = "str";
var i = 0;
while(i < 6)
{
print(a[i]);
i++;
}
// Expect: str
// Expect: 1
// Expect: 2Class declarations can contain methods and a constructor - init(). init() is called during the creation of an instance from a class. It returns the newly created instance and therefore cannot return a custom value.
class Human
{
init()
{
print("I am alive!");
}
quote() // Method declaration
{
print("Bla bla");
}
}class Human
{
init()
{
print("I am alive!");
this.dialogue = "I have nothing interesting to say.";
}
talk()
{
print("Hi, I am " + this.name ".");
}
}
var person = Human(); // Print: I am alive!
person.name = "Billy";
person.talk(); // Print: Hi, I am Billy.
this.dialogue; // "I have nothing interesting to say."Inherit methods from other classes. Overriden methods are available using base.method() syntax.
class Artificer
{
constructStuff()
{
print("I made a drill using scrap from the wall!");
}
yell()
{
print("I am an artificer!");
}
}
class Alchemist : Artificer
{
brew()
{
print("I made a potion!");
}
yell()
{
print("I am an alchemist!");
base.yell();
}
}
var a = Alchemist();
a.brew(); // Print: "I made a potion!"
a.constructStuff(); // Print: "I made a drill using scrap from the wall!"
a.yell(); // Print: "I am an alchemist!" "I am an artificer!"