-
Notifications
You must be signed in to change notification settings - Fork 1
Basics
Zahir Hadi Athallah edited this page Jul 8, 2022
·
8 revisions
write("Hello, World")
// it will print "Hello, World" on the console
// in DreamScript, the Variable uses "const, var, let" Syntax to declare a Variable
// but, you can use "set" Scope to declare a type of the Variable
// or, if the variable is an array, use "setArray" Scope
// Example :
// Without "set" Scope :
const myName = "Zahir"
var myName = "Zahir"
let myName = "Zahir"
// With "set" Scope :
set const myName = "Zahir" : (String)
set var myName = "Zahir" : (String)
set let myName = "Zahir" : (String)
// Array Variable without "setArray" Scope :
const myArray = [10, 20, 30, "Zahir"]
// Array Variable with "setArray" Scope :
set const myArray: 10, 20, 30, "Zahir" = (Number | String)
### Function
```javascript
func Dreamscript() {
writeLog("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 Zahir {
struct(height, width)
this.height = height;
this.width = width;
}
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
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