Skip to content
Zahir Hadi Athallah edited this page Aug 21, 2022 · 8 revisions

Hello World

write("Hello, World")

// it will print "Hello, World" on the console

Variables

// in DreamScript, the Variable uses "const, var, let" Syntax to declare a Variable
// but, you can use "set" Keyword to declare a type of the Variable
// or, if the variable is an array, use "setArray" Keyword
// Example :

// Without "set" Keyword :

const myName = "Zahir"

var myName = "Zahir"

let myName = "Zahir"


// With "set" Keyword :

set const myName = "Zahir" => (String)

set var myName = "Zahir" => (String)

set let myName = "Zahir" => (String)

// Array Variable without "setArray" Keyword : 

const myArray = [10, 20, 30, "Zahir"]

// Array Variable with "setArray" Keyword : 

set const myArray: 10, 20, 30, "Zahir" => (Number | String)

Function

func Dreamscript() {
	write("Function in Dreamscript")
}

Dreamscript()

// it will print "Function in DreamScript" on the console from the Dreamscript() Function

// the Function also can use with type checking
// Example :

func multiply(valueA = Number, valueB = Number) {
	ret() valueA * valueB
}

write(multiply(1, 2)) // Output : 2

write(multiply("2", 1)) // It will Throws a TypeErrors

Class

class Zahir {
	struct(height, width)
	this.height = height;
	this.width = width;
 }

Looping

Dreamscript Use repeat() Function to make For...I Statements easier

repeat(var i amount: 20 times) {
	write("Hello, World", i)
}


// it will be looping the "Hello, World" for 20 times

For...Of and For...In Statements Loops

DreamScript use every() Function to make for...of and for...in Statements easier

// For...Of Statements Examples

setArray const array: 10, 20, 30 => (Number)

every(value of array) {
  write(value);
}

// it will print to the console :
// 10 
// 20
// 30


set let name = "Zahir" => (String)

every(value of name) {
  write(value);
}

// it will print to the console:
// "Z"
// "a"
// "h"
// "i"
// "r"

// For...In Statements Examples

const scores = { Zahir: 90, Jimmy: 100, Bagas: 85, Ariq: 75};

every(students in scores) {
    write(`${students}` + ' scored ' + `${scores[students]}` + ' points');
}

// it will print to the console :
// Zahir scored 90 points
// Jimmy scored 100 points
// Bagas scored 85 points
// Ariq scored 75 points

Tuple

// in DreamScript, tuple can be declared with "tuple" keyword
// Examples : 

tuple myData: String | Number = ("Zahir", 15)

let [name, age] = myData

write(name)
write(age)

// Output : 
// Zahir
// 15
Clone this wiki locally