Skip to content

Commit 8017b0a

Browse files
author
Philipp Gersch
authored
Add files via upload
1 parent 4b54ecb commit 8017b0a

11 files changed

Lines changed: 629 additions & 0 deletions

File tree

Examples/demos/Calculator

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#Simple calculator with input#
2+
#Should also be an example for functions#
3+
4+
calculate = {
5+
num1 = $0; #Better names#
6+
num2 = $1;
7+
operator = $2;
8+
9+
ifnot (($num1 typeof num) or ($num2 typeof num))
10+
{
11+
println "Error";
12+
return;
13+
};
14+
15+
if ($operator == +)
16+
{
17+
return ($num1 + $num2);
18+
};
19+
if ($operator == -)
20+
{
21+
return ($num1 - $num2);
22+
};
23+
println "Error, unknown operator: " $operator;
24+
};
25+
26+
print "Enter first number: ";
27+
num1 = (input);
28+
print "Enter second number: ";
29+
num2 = (input);
30+
print "Enter operator (+, -): ";
31+
operator = (input);
32+
33+
println "Calculating...";
34+
println (call $calculate $num1 $num2 $operator);

Examples/demos/Selection Sort

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#Selection sort example by DevKev for version 1.9.10#
2+
3+
unsorted = [];
4+
sorted = [];
5+
record = 99999;
6+
index = -1;
7+
8+
for i 200 {
9+
unsorted[$i] = (int ((random) * 1000));
10+
};
11+
12+
println $unsorted;
13+
14+
loop
15+
{
16+
for i (length $unsorted)
17+
{
18+
if ($unsorted[$i] lt $record)
19+
{
20+
record = $unsorted[$i];
21+
index = $i;
22+
};
23+
};
24+
25+
push $unsorted[$index] $sorted;
26+
pop $unsorted $index;
27+
record = 99999;
28+
29+
if ((length $unsorted) == 0)
30+
{
31+
break;
32+
};
33+
};
34+
35+
println "Done";
36+
println $sorted;

Examples/demos/hangman

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
#Hangman by DevKev for version 1.9.10#
2+
3+
words = [tree devscript script java command block array thread];
4+
word = "";
5+
guessed = [];
6+
wordsplit = [];
7+
blacklist = [];
8+
9+
drawScreen = {
10+
try {
11+
exec cls;
12+
clearConsole;
13+
};
14+
15+
allright = $true;
16+
for i (length $wordsplit) {
17+
if ($guessed[$i] != " ") {
18+
print $guessed[$i] "\t";
19+
} else {
20+
print "_\t";
21+
allright = $false;
22+
};
23+
};
24+
25+
if $allright {
26+
call $drawEndScreen $true;
27+
return;
28+
};
29+
30+
println "\n\n";
31+
println "LIFE [" $life "]";
32+
characters = "";
33+
for i (length $blacklist) {
34+
characters = (($characters + " ") + $blacklist[$i]);
35+
};
36+
println "Wrong Guesses: " $characters;
37+
println;
38+
};
39+
40+
drawEndScreen = {
41+
try {
42+
exec cls;
43+
clearConsole;
44+
};
45+
46+
if $0 {
47+
println " \tY O U W O N !";
48+
} else {
49+
println " \tY O U L O S T !";
50+
};
51+
println;
52+
println "\tThe word was: '" $word "'";
53+
println "\tYou had " $life " lives left";
54+
println "\n\tPlay again? Press [ENTER]";
55+
input;
56+
call $chooseWord;
57+
call $drawScreen;
58+
};
59+
60+
guess = {
61+
char = $0;
62+
for i (length $blacklist) {
63+
if ($blacklist[$i] == $char) {
64+
println "lool";
65+
return $false;
66+
};
67+
};
68+
right = $false;
69+
for i (length $wordsplit) {
70+
if ($wordsplit[$i] == $char) {
71+
guessed[$i] = $char;
72+
right = $true;
73+
};
74+
};
75+
return $right;
76+
};
77+
78+
chooseWord = {
79+
life = 10;
80+
word = $words[?];
81+
guessed = [];
82+
wordsplit = [];
83+
blacklist = [];
84+
for i (stringLength $word) {
85+
wordsplit[$i] = (charAt $i $word);
86+
guessed[$i] = " ";
87+
};
88+
};
89+
90+
addToBlacklist = {
91+
for i (length $blacklist) {
92+
if ($blacklist[$i] == $0) {
93+
return;
94+
};
95+
};
96+
push $0 $blacklist;
97+
};
98+
99+
call $chooseWord;
100+
life = 10;
101+
loop {
102+
call $drawScreen;
103+
print "Guess a character: ";
104+
character = (input);
105+
106+
if ((stringLength $character) gt 0) {
107+
character = (charAt 0 $character);
108+
right = (call $guess $character);
109+
ifnot $right {
110+
life = ($life - 1);
111+
call $addToBlacklist $character;
112+
if ($life == 0) {
113+
call $drawEndScreen $false;
114+
};
115+
};
116+
};
117+
}
118+
119+
120+
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#[EXAMPLE 1: BASIC COMMAND SYNTAX]#
2+
3+
#
4+
As you can see, you can put comments in your script by putting the text in between two "hashtags"
5+
Comments are being completely ignored, so you can put them basically everywhere.
6+
#
7+
8+
#In general, there is a command, that accepts certain arguments:
9+
Here we have a "println" command, that accepts strings or any
10+
other datatype. All commands are separated by a ";" and arguments are separated by a space character.
11+
You can use the "help" command to list all available commands and their arguments#
12+
help;
13+
println "Hello";
14+
15+
16+
#Strings are also recognized without the Quotation marks:#
17+
println Hello;
18+
19+
20+
#But they are helpful if you want to pass Strings with spaces#
21+
println "Hello World";
22+
23+
24+
#You can "wrap" multiple commands as arguments for other
25+
commands by putting the command in between "(" and ")"
26+
Here, we add 2 and 2 (=4) and printing the result:
27+
(Remember, the + is just another command, but the command name is
28+
shifted to the right. Otherwise, it would look like this: "+ 2 2". Not very readable.#
29+
println (2 + 2);
30+
31+
#We can also do more complex command "wrapping" and print it
32+
But remember, too much of something is never good better split this up with variables (Covered in example 2)#
33+
println (int ((random) * 1000));
34+
35+
#To format text, you can just put \n and \t inside strings#
36+
println "This is a line\nAnd another line. \tTab";

Examples/tutorials/2 Variables

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#EXAMPLE 2: VARIABLES#
2+
3+
#You can declare and modify variables using the "=" command (Command name is shifted by one to the right)
4+
You can put any character into the variable name, except: "$", ".", ";" and obviously space characters.
5+
Reserved characters like "[", "]", """, "<", ">", "{", "}" may cause weird behaviors.
6+
So in general, you should avoid reserved characters#
7+
foo = "Some text";
8+
2 = "More text";
9+
=*2_&] = "Why would you even name your variable like this?";
10+
11+
12+
#You can access variables by using the "$" character, followed by the variable name#
13+
println $foo;
14+
println $=*2_&];
15+
println $2;
16+
17+
18+
#Variables are entirely replaced by their respective value, so theoretically, you can even do this.
19+
This example will store the command name in a variable and execute it with the given argument:#
20+
commandNameAsVariable = println;
21+
$commandNameAsVariable $foo; #<- Replaced by 'println "Some text"' and executed at runtime! #
22+
23+
24+
#To read variables, you use the "$" sign. But you don't use it to modify variables
25+
Here we change the value of the variable "foo" to "Changed the text!"#
26+
foo = "Changed the text!";
27+
println $foo;
28+
29+
30+
#This rule of variable modification also applies to arrays (Tutorial 4) and Objects (Tutorial 7):#
31+
#We print the first array element ("1") but we will change it to "10"#
32+
array = [1 2 3]; #More on this in tutorial 3#
33+
println $array[0]; #<- Access with $ sign#
34+
array[0] = 10; #<- Modify without $ sign#
35+
$array[0] = 10; #This will create a variable with the name "10", since the value of $array[0] is 10#
36+
println $array[0];
37+
println array[0]; #<- This will just print "array[0]", but not the actual value. You forgot the "$"!#
38+
39+
obj = (new-object {}); #More on this in tutorial 5#
40+
obj.x = 10;
41+
println $obj.x;
42+
43+
44+
#You can list all accessible variables and their Block for debug purposes by executing this command#
45+
listvars;
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#CONDITIONAL EXPRESSIONS BASICS by DevKev for version 1.9.10#
2+
3+
#To create if statements, you can use the "if [boolean] [block]" command
4+
Remember, unlike java or similar languages, you still need to use ";" to terminate a command even if it ends with a "}"#
5+
variable = $true;
6+
if $variable {
7+
println "The variable is true!";
8+
};
9+
10+
11+
#If statements work like in most programming languages:#
12+
if $false {
13+
#...#
14+
} else {
15+
#...#
16+
};
17+
18+
19+
#"elseif" is also possible#
20+
if $false {
21+
#...#
22+
} elseif $true {
23+
#...#
24+
} else {
25+
#...#
26+
};
27+
28+
29+
#You can also use the command [boolean] ? [???] [???]" as ternary expression
30+
If the condition is true, the 3rd argument is returned, otherwise the 4th#
31+
condition = $true;
32+
println ($condition ? "Condition is true" "Condition is false");
33+
34+
35+
#To compare two variables you can use the following commands with the two example Variables $var0 and $var1:
36+
"$var0 == $var1" <- Returns $true, if $var0's toString() equals $var1
37+
"$var0 != $var1" <- Returns $true, if $var0's toString() does not equal $var1
38+
"$var0 lt $var1" <- Returns $true, if $var0 is less than $var1 (Works only with numbers)
39+
"$var0 lteq $var1" <- Returns $true, if $var0 is less or equal than $var1 (Works only with numbers)
40+
"$var0 gt $var1" <- Returns $true, if $var0 is greater than $var1 (Works only with numbers)
41+
"$var0 gteq $var1" <- Returns $true, if $var0 is greater or equal than $var1 (Works only with numbers)#
42+
43+
var0 = 22;
44+
var1 = 12;
45+
if ($var0 gt $var1) {
46+
println "var0 is greater than var1";
47+
};
48+
49+
50+
#You can also use logical operators "and" and "or"#
51+
result0 = ($true and $false);
52+
println $result0;
53+
result1 = ($true and $false or $true);
54+
println $result1;
55+
result1 = (($true and $false) or ($true and $true));
56+
println $result1;
57+
58+
#The following example prints, if x is inbetween 10 and 20 or less than 0#
59+
x = 20;
60+
if (($x gteq 10) and ($x lteq 20) or ($x lt 0)) {
61+
println "x is between 10 and 20 or less than 0";
62+
} else {
63+
println "x is less than 10 and greater than 20 and above zero";
64+
};
65+

0 commit comments

Comments
 (0)