-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathNew Scripting Features.txt
175 lines (138 loc) · 4.13 KB
/
New Scripting Features.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
- New Keywords
- switch
Equivalent to "alternative".
- default
Equivalent to "others".
- continue
Usage similar to "break", but only skips the current iteration of the loop.
- for
Used to declare a for loop.
- each
Used in conjunction with "for" to create a for each loop.
- const
Used to declare a constant.
- New Features
- Constant Variables
Variables whose values cannot be changed.
Any attempt to do so will throw a compile-time error.
Examples:
const a = 50;
let b = a + 80; //OK
ascent (i in 0..a) {} //OK
a = 100; //ERROR
a *= 4; //ERROR
for (const a = 0; a < 10; a++) {} //ERROR
for (const a = 0; a < 10; b++) {} //OK
- Function Overloading
Functions and tasks can be re-declared with different amount of parameters.
Example:
function DoStuff() {
return 0;
}
function DoStuff(arg0) {
return 100;
}
function DoStuff(arg0, arg1, arg2, arg3) {
return arg0 + arg1 + arg2 + arg3;
}
DoStuff(); //Returns 0
DoStuff("foo"); //Returns 100
DoStuff(1, 2, 3, 4) //Returns 10
- Loop Continues
Skips the current iteration of the loop it was used in.
Example:
ascent (i in 0..10) {
if (i % 2 == 1) { continue; }
WriteLog(i)
}
//Output: 0 2 4 6 8
- For Loops
Read "Statements and Flow Controls" or something similar on a decent C/C++ tutorial.
Examples:
for (let a = 0; a < 6; a++) {}
let b = 0;
for (b = 6; b >= -10; b--) {}
for (let c = []; length(c) < 10; c = c ~ [rand(-10, 10)]) {}
- For Each Loops
Iterates through an array.
Note: You can use either "in" or a colon, it doesn't matter.
Examples:
let sum = 0;
for each (iDigit in [0, 1, 2, 3, 4, 5]) {
sum += iDigit;
}
let objArray = [obj1, obj2, obj3, obj4];
for each (let iObj : objArray) {
Obj_Delete(iObj);
}
for each (iChar in "ph3sx") {
WriteLog(iChar);
}
let numArray = [0, 1, 2, 3];
for each (iNum in numArray) {
numArray = numArray ~ [rand(0, 10)];
WriteLog(iNum);
}
//The code above will produce 0, 1, 2, and finally 3, regardless of modifications to numArray during looping.
- Local Blocks
What had been:
local {
//code....
}
Can now be reduced to simply:
{
//code....
}
In short: "local" can be omitted.
- Ternary Statements
Read "Statements and Flow Controls" or something similar on a decent C/C++ tutorial.
let variable = expression1 ? expression2 : expression3;
**The ternary operator has the lowest operator precedence.
- Bitwise Operators
Operators are usable in addition to functions.
-> Higher operator precedence
NOT (~)
AND (&)
OR (|)
XOR (^^)
Left Shift (<<), Right Shift (>>)
-> Lower operator precedence
- Optimizations
- The engine will now try to perform basic optimizations on maths expressions.
Examples:
a = 5 + 5 - 1; -> a = 9;
a = 5 * 8 / 7; -> a = 5.714286;
a = func(b) + 5 % 10; -> a = func(b) + 5;
- Loops and blocks without code will now be optimized away during script compiling.
Examples:
while (true) {}
for (let i = 0; i < 10; i++) {}
ascent (i in 0..100000000000) {}
{
}
loop (1000) {
}
for each (i in "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa") {}
- Loops containing a single yield will be automatically transformed into a wait.
Examples:
loop (60) { yield; } //-> wait(60);
let a = 100;
loop (a * 2 + 60 - 20) { //-> wait(a * 2 + 60 - 20);
yield;
}
- Behaviour Changes
- "break;" will no longer cause catastrophes when used outside loops, as its scope of operation no longer extends beyond a task/function.
- Backslash escapes (\\) can now be used in char/string values.
- A hexadecimal char literal (\x[hex]) can now be used in char/string values.
Example:
"\x74" -> "t"
'\x3042' -> 'あ'
"\x042\x5f" -> "B_"
- One-lined statements.
Example:
ascent (i in 0..10) WriteLog(i);
if (true) a += 10;
else a -= 4;
Can be used everywhere except function/task/sub declarations, @ blocks, and local{} blocks.
- Others
- Some default functions now allow for variadic argument counts.