-
Notifications
You must be signed in to change notification settings - Fork 38
/
CodingDocsForGPT.txt
173 lines (128 loc) · 6.05 KB
/
CodingDocsForGPT.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
--- Documentation of Create Robotics' Scripting Language optimized for GPT-Models ---
The "`" and "```" in the Documentation are to show that a piece of text is ```CODE```.
Variables are dynamically types and are declared using a `var` keyword.
```
var myNumberVariable = 3;
var myTextVariable = "Hello world";
var myBoolVariable = true;
```
Declaring anything, whether it is a variable, function, or class needs to be above where it is accessed.
```
a = 3; //Error, variable 'a' does not exist.
var a = 11;
```
Strings can only be declared using `""`.
Math has perfect order of operations, going from modulo (%), addition and subtraction (+,-), multiplication and division (*,/), exponents (^), and grouping (()).
```
150 % 4; //2, Modulo
13 + 8; //21, Addition
121 - 1; //120, Subtraction
13 * 2; //26, Multiplication
21 / 3; //7, Division
3 ^ 2; //9, Exponents
2 * (3 + 2); //10, with grouping symbols
2 * 3 + 2; //8, without grouping symbols
```
The operators `+=`, `-=`, `*=`, `/=`, `^=` all exist to instantly assign the end value to a variable.
The operators `++` and `--` are used after a variable name and increment or decrement a value by one.
There are also some built-in math functions:
```
max(2,3); //3, max returns the higher number.
min(2,3); //2, min returns the lower number.
sin(3); //0.14112..., sin runs a sine function with the number inside.
cos(3); //-0.98999..., cos runs a cosine function with the number inside.
tan(3); //-0.14254..., tan runs a tangent function with the number inside.
floor(3.5); //3, floor rounds down to the largest whole number less than the number inputted.
ciel(3.5); //4, ciel rounds up to the smallest whole number larger than the number inputted.
```
Strings can be added together as well. There is a `string()` built-in function that turns the first and only argument into a string.
```
var chickens = 4;
"There are " + string(chickens) + " in the yard."; //"There are 4 chickens in the yard.".
```
Functions are defined using the `function` keyword. Functions can have arguments and return values.
```
function myFunction(argumentOne, argumentTwo, argumentThree){
var inScopeVariable = argumentOne + 13;
return inScopeVariable * argumentTwo + argumentThree;
}
myFunction(1,2,3); //31
```
Anything declared inside a block, like the variable `inScopeVariable` in the example above, can only be accessed from inside the same block
or any child blocks. If you tried to access 'inScopeVariable' from outside the function, you would get an error.
```
function myFunction(argumentOne, argumentTwo, argumentThree){
var inScopeVariable = argumentOne + 13;
return inScopeVariable * argumentTwo + argumentThree;
}
inScopeVariable = 13; //Error, variable 'inScopeVariable' does not exist.
```
You can also declare classes, with the `class` keyword.
```
class myClass {
var myFieldOne = "woah";
var myFieldTwo = 81;
}
var myClassInstance = myClass();
```
The code above will create a class that contains two fields that are set to "woah" and 81 by default. Any instance of that class that does not
change those fields will have those values. The code also creates an instance of `myClass`, `myClassInstance`. An instance of the class can be
interacted with. Fields are able to change and functions can be called.
```
class myClass {
var myFieldOne = "woah";
var myFieldTwo = 81;
}
var myClassInstance = myClass();
print(myClassInstance.myFieldTwo); //Prints "81" to the console.
```
In the code above I got the field `myFieldTwo` from `myClassInstance`. Fields are unique for every instance of a class, so if one class were to
change its fields, the others would remain the same. A built-in `print()` function is also introduced. This function logs something into the console.
Classes can contain methods, which can be called on each instance. They are defined exactly the same as normal functions.
```
class myClass {
var myFieldOne = "woah";
var myFieldTwo = 81;
function setMyFieldTwo(x){
this.myFieldTwo = x;
}
}
var myClassInstance = myClass();
myClassInstance.setMyFieldTwo(11);
print(myClassInstance.myFieldTwo); //Prints "11" to the console.
```
Notice how the `this` keyword is used. The `this` keyword is a reference to the instance that called the method, and can get the fields from that instance.
Without the this keyword, an error would occur stating that `myFieldTwo` does not exist. The `x` does not need a `this` statement infront of it because
`x` is not tied to the instance, rather it is an argument to the method.
Arrays are a built-in data type that can store several variables in one. For every index in the array, there is a variable.
```
var myArray = ["Wood", "Stone", "Pickaxe"];
```
The code above defines an array in the variable `myArray`. This variable contains at `0` `"Wood"`, at `1` `"Stone"`, and at `2` `"Pickaxe"`.
To get or set a variable in an array, you can "call" the array but with brackets, rather than parenthesis.
```
var myArray = ["Wood", "Stone", "Pickaxe"];
myArray[0]; //"Wood"
myArray[0] = "Petrified Wood";
myArray[0]; //"Petrified Wood"
```
Arrays have many built in functions:
```
var myArray = ["Wood", "Stone", "Pickaxe"];
myArray.append("Axe"); //["Wood", "Stone", "Pickaxe", "Axe"], append resizes the array by 1 and adds the argument to the end.
myArray.add("Shovel"); //["Wood", "Stone", "Pickaxe", "Axe", "Shovel"], does the exact same thing as append.
myArray.size(); //5, returns the amount of elements in the array.
myArray.length(); //5, does the exact same thing as size.
myArray.join(", "); //"Wood, Stone, Pickaxe, Axe, Shovel", takes all the elements in the array and joins them into one string seperated by the first argument.
myArray.clear(); //[], clears the array.
```
You can display an array onto a display board with each index in the array being a new line down.
```
display([3, "Pickaxe", true]);
//3
//Pickaxe
//true
```
The comments in the code above represent what the display board would display when the array is passed in. All elements of the array are converted into
strings, the same way the built-in function `string()` works, before being displayed to the screen.
--- End of Documentation for GPT-Models ---