You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+2-174Lines changed: 2 additions & 174 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -27,178 +27,6 @@ Command line arguments are:<br>
27
27
- If only --nogui is given, the jar opens the default editor, stored in Editor.txt
28
28
29
29
# Syntax
30
-
In this big section, I will try to bring you near the usage and capabillities of the DevScript, so you can use them for your own projects
30
+
Examples and tutorial on how the syntax work can be found [here](Examples)<br>
31
+
Or just download the .jar from the releases and start tinkering with the inbuild editor!
31
32
32
-
## Commands
33
-
34
-
### Data Types
35
-
There are 6 main data types: _STRING, BOOLEAN, BLOCK, DICTIONARY, ARRAY, OBJECT_ (OBJECT is any java object, except the primitive data types)<br>
36
-
There are also 4 sub- data types: _ANY, ARRAY_ANY, INTEGER, FLOAT, CONTINUE_<br>
37
-
Sub- data types are not considered as 'real' data types. They are only important in specific situations<br>
38
-
39
-
This would be a typical command, that expects certain argument types:
40
-
> exampleCommand [BLOCK][ANY][STRING][CONTINUE];
41
-
42
-
The example command expects a block (Discussed in section _Block_) as the first argument, then any other type and Strings.
43
-
The [CONTINUE] type means, there is no limitation for the last argument in number,<br>
44
-
so you could pass an infinite amount of STRINGs (Because the last type before CONTINUE was a string).
45
-
46
-
### Command Syntax
47
-
The whole syntax is based on commands. These act like functions, that means, they can return values and accept arguments and are separated with ';'.<br>
48
-
Example for the command println:
49
-
- This command expects strings without limitation in number: _println [STRING][CONTINUE]_ and returns $null, that means nothing.
50
-
> println "Hello World" "And another line";
51
-
52
-
Command names can also be shifted, like the _[string] + [string]_ command to make the code more readable.
53
-
So, instead of writing + 1 1 ('+' or 'add' being the command here) we can shift the command one section to the right:
54
-
> 1 + 1; <- Better to read and write!
55
-
56
-
This command returns the sum of its two arguments.
57
-
But this command alone does not do very much. How do you use the new, returned value?
58
-
Look at this example:
59
-
> println (1 + 1);
60
-
61
-
This is the same as:
62
-
> println 2;
63
-
64
-
Commands can be combined with others with parantheses.
65
-
> println (1 + (4 / 2));
66
-
67
-
Note that if you want to use $null as a returned value, the program will throw an error, because $null is not interpreted as argument,<br>
68
-
so the interpreter thinks this command has not arguments: use [STRING] != use
69
-
> use (println "null?!")<br>Error at [println "null?!"] No such command use.
70
-
71
-
## Variables
72
-
73
-
Variables can get declared with the _[STRING] = [ANY]_ command.
74
-
And you can access them with a $ sign, followed by the variable name:
75
-
> foo = 10;<br>println (1 + $foo);
76
-
77
-
There are also a few inbuild variables:
78
-
´$true, $false and $null´
79
-
80
-
## Blocks
81
-
Blocks are code, wrapped inside two curly braces { }.
82
-
In theDevScript Language, blocks are treated as a data type [BLOCK]. Basically, a block only consists of a String of code and
83
-
their main goal is to provide functions.
84
-
To define a function, you create a variable as usual (With the "=" command), since -as already mentioned- blocks are just data types and can get passed as command argument.
85
-
> function = {<br>println "I am a function :)";<br>println "But how do you execute me?"<br>};
86
-
87
-
To execute a function, use the _"call [BLOCK][CONTINUE] ..."_ command:
88
-
> call $function;
89
-
90
-
Functions can also accept arguments (This is why the call command has some more optional arguments).<br>
91
-
Inside the function, the passed argument values are disguised as $0, $1, $2 and so on, depending on how much arguments you pass.
Last but not least, functions can also return value with the command _return [ANY]_. If you use this command, the "call" command has now a new return value.
95
-
> add = {<br> #Adds argument0 and argument1 and return new new value#<br> return ($0 + $1);<br>}<br>println (call $add 1 1);
96
-
97
-
Please take your time to understand this section, as it can get quite complex.
98
-
## Arrays
99
-
Arrays can get declared as empty, or filled.
100
-
All arrays are dynamic. They can get altered with ´push [ANY][ARRAY]´ and ´pop [STRING]´.
101
-
102
-
> emptyArray = [];<br>
103
-
filledArray = ["string1" "string2" $true (20 + 12) {println "Arrays can hold blocks. They are data types :)"}];<br>
104
-
newObject = "This is a String";<br>
105
-
push $newObject $emptyArray;
106
-
107
-
As you can see, you can set multiple data types to one array.
108
-
However if an array -for example- only has Strings, the type of the array will be STRING.
109
-
- $filledArray would have the type ANY, since it contains multiple, different data types, such as STRING, BOOLEAN, BLOCK
110
-
- $emptyArray's type would be STRING: It has only strings in it.<br>
111
-
_Tip: To check a variable for a type, you can use the [ANY] typeof [STRING] command.<br>
112
-
The [STRING] argument would be the type written out. Different types are listed in the Section: Data Types. Minor and Major work.<br>
113
-
$filledArray typeof "any" would return true._
114
-
115
-
Also arrays with multiple dimensions are possible. You access an array index like in any other programming language:
And if we are discussing Arrays and you already know about blocks, you may want to learn how to use for loops etc.:
119
-
This would be a typical for- loop:
120
-
>for i 10 {<br>println "This text will be printed 10 times!";<br>println "Iteration: " $i;<br>};
121
-
122
-
The first argument of the _for [STRING][STRING][BLOCK]_ command is the variable name starting at zero.
123
-
>array = ["John" "Peter" "Chris"];<br>for i (length $array) {<br>println $array[$i];<br>};
124
-
125
-
## If
126
-
Here is an example of an if- statement:
127
-
>if (10 == 11) {<br>println "Condition is true";<br>} {<br>println "Condition is false";<br>};
128
-
129
-
But keep in mind, that the parantheses after the if are just wrapping another command ([ANY] == [ANY]) and are not there like in Java or other languages.
130
-
>if $true {<br>println "true"<br>};
131
-
## Thats it!
132
-
Now, if you understand the basic syntax and command usage, you are ready to start!
133
-
It may also be handy to notice, that this script also supports threading.
134
-
You can use the _help_ command for a list of commands, but I will print them below, so you can have a look.
135
-
136
-
# All default commands
137
-
138
-
LIBRARY 'Native' (65 Commands)<br>
139
-
println [ARRAY_ANY] Prints any object's toString() method in a new line<br>
140
-
print [ARRAY_ANY] Prints any objecs's toString() method<br>
141
-
[STRING] = [ARRAY_ANY] Defines a variable. Access it with $variableName<br>
142
-
[ARRAY_ANY] === [ANY][STRING][object] === [array][index][index] ... Like '=' for arrays<br>
143
-
[STRING] + [STRING] Adds two numbers and returns the result, if either of the arguments is not a number, two strings are added<br>
144
-
[STRING] - [STRING] Subtracts two numbers<br>
145
-
[STRING] * [STRING] Multiplies two numbers<br>
146
-
[STRING] / [STRING] Divides two numbers<br>
147
-
exec [STRING] Executes a shell command<br>
148
-
script [STRING] Executes a new script sub-process with its parent in- and outputs<br>
149
-
length [ANY] Returns the size of the array<br>
150
-
pop [ANY][STRING] Removes the specified index of the array<br>
151
-
createdict Returns an empty dictionary<br>
152
-
get [DICTIONARY][STRING] get [dictionary][key] Returns the corresponding value of the key inside the dictionary<br>
153
-
set [DICTIONARY][STRING][ARRAY_ANY] set [dictionary][key][object]<br>
154
-
remove [DICTIONARY][STRING] remove [dictionary][key] Returns false, if there was no associated key with the name.<br>
155
-
clear [DICTIONARY] clear [dict] Removes all values from the dictionary<br>
156
-
isEmpty [DICTIONARY] Checks, if a dictionary is empty<br>
157
-
push [ARRAY_ANY][ANY] Pushes a new value into the array<br>
158
-
[STRING] lt [STRING] Returns true, if argument 1 is less than 2 (If the arguments are not numbers, it checks the length of the string)<br>
159
-
[STRING] lteq [STRING] Returns true, if argument 1 is less or equal than 2 (If the arguments are not numbers, it checks the length of the string)<br>
160
-
[STRING] gteq [STRING] Returns true, if argument 1 is grater or equal than 2 (If the arguments are not numbers, it checks the length of the string)<br>
161
-
[STRING] gt [STRING] Returns true, if argument 1 is grater than 2 (If the arguments are not numbers, it checks the length of the string)<br>
162
-
[ANY] == [ANY] Returns true, if argument 1 and 2 are equal<br>
163
-
[ANY] != [ANY] Returns true, if argument 1 and 2 are not equal<br>
164
-
not [BOOLEAN] Inverts a boolean<br>
165
-
[BOOLEAN] and [BOOLEAN][ANY] Chain boolean conditions: if ($true and $true or $false) {...<br>
166
-
random Returns a random number between 0 and 1<br>
167
-
[BOOLEAN] or [BOOLEAN][ANY] Chain boolean conditions: if ($true or $true and $false) {...<br>
168
-
int [ANY] Casts the given value into java.lang.Integer<br>
169
-
float [ANY] Casts the given object into java.lang.Float<br>
170
-
string [ANY] Casts the given value into java.lang.String<br>
171
-
call [BLOCK][ARRAY_ANY] Executes a function (Variable that is a block: x = { function code... }. You can also pass arguments. Access them inside the block with $0 $1 etc...Returns the returned value of the function<br>
172
-
if [BOOLEAN][BLOCK][BLOCK] If statement<br>
173
-
if [BOOLEAN][BLOCK] If statement<br>
174
-
ifnot [BOOLEAN][BLOCK] Inverted If-statement<br>
175
-
for [STRING][STRING][BLOCK] For loop: for i 10 {...}<br>
176
-
loop [BLOCK] Infinite loop. Use the break command inside it.<br>
177
-
break Breaks out of the next found loop in the stack. If no loop was found, this command interrupts the block<br>
178
-
kill [STRING] Stops the application and throws an error message<br>
179
-
input Reads input from the set input stream<br>
180
-
[ARRAY_ANY] typeof [STRING] Argument 2 is a string representation of the type like the command arguments. There are two adittional useful types: int and float<br>
181
-
wait [STRING]<br>
182
-
thread [STRING][BLOCK] Runs a separate thread along the process<br>
183
-
kill [BLOCK]<br>
184
-
pause Pauses the block, the command is executed in<br>
185
-
pause [BLOCK] Pauses the specified block, if it is running in a separate thread.<br>
186
-
waitfor [BLOCK] Waits for a block to finish<br>
187
-
wake [BLOCK] Wakes the specified thread<br>
188
-
alive [BLOCK]<br>
189
-
return [ARRAY_ANY] Searches the first occurrence of a block that is a function and returns its given value or null (Block execution gets terminated)<br>
help Prints all the available commands with a brief explanation and arguments<br>
197
-
import [STRING] Imports a library from a compiled .jar file. The class should extend com.mygdx.devkev.devscript.raw.Library and be named CustomLibrary<br>
198
-
You can use a * to reference the current path the process is executed in (*/library.jar<br>
199
-
getFile [STRING] Returns a java.io.File object<br>
200
-
fileExists [OBJECT] Checks if a file exists<br>
201
-
deleteFile [OBJECT] Deletes a file. You can use this command, if you want to clear a files content and append lines with the writeFileLine command<br>
202
-
writeFileLine [OBJECT][STRING][file][content] Appends a new line to the file<br>
203
-
listDirectory [OBJECT] Returns an array containing all files inside this directory<br>
0 commit comments