Login

Fancade Wiki

Fix some minor mistakes

... ...
@@ -1,4 +1,4 @@
1
Editor Scripting is an experimental feature that can be used to build levels by programmatically placing blocks. The editor is currently available in the beta version of [[ Fancade Web ]] by entering the `EditorScript` command in the [command line](fancade-web#command-line).
1
Editor Scripting is an experimental feature that can be used to build levels by programmatically placing blocks. The editor is currently available in the beta version of [[ Fancade Web ]] by entering the `EditorScript` command in the [command line](/wiki/fancade-web#command-line).
2 2
3 3
## Getting Started
4 4
Let's create a new level and enter the `EditorScript` command. You will be greeted by a simple code editor with some examples in place. The code might seem unfamiliar at first, because it is written in JavaScript. But don't be scared, because we will learn the basics in this tutorial!
... ...
@@ -11,13 +11,14 @@ So let's look at our first example.
11 11
setBlock(x, y, z, prefabIndex);
12 12
```
13 13
We can ignore the first line, since it begins with `//`. This makes the editor ignore any code in the current line, but it can give us some hints on what the following line does.\\
14
The second line starts with the function `setBlock`. You can imagine this as placing a script block with the aforementioned name. A list of these functions can be found in the [examples](fancade-web#editor-scripting). The following text represents the inputs given to this function, separated by `,` and enclosed by brackets. So to put this in [[visual scripting]] therms, we are placing a block called `setBlock` and give it the inputs `x`, `y`, `z` and `prefabIndex`.
14
The second line starts with the function `setBlock`. You can imagine this as placing a script block with the aforementioned name. A list of these functions can be found in the [examples](/wiki/fancade-web#editor-scripting). The following text represents the inputs given to this function, separated by `,` and enclosed by brackets. So to put this in [[visual scripting]] therms, we are placing a block called `setBlock` and give it the inputs `x`, `y`, `z` and `prefabIndex`.
15 15
16 16
But those inputs were actually just placeholders, so let's replace them with some actual values!
17 17
```js
18
// Set block at position (0, 0, 0) in level or open block
18 19
setBlock(0, 0, 0, 3);
19 20
```
20
Copy this code and paste it in the editor, then hit `Run` and `Save and Close`. As you might have guessed, this puts a block on the coordinates `0, 0, 0`. The fourth value is the unique identifier for the Grass block to be placed. There is a list of unique ids for each built-in block, but what if we want to place a custom block instead?
21
Copy this code and paste it in the editor, then hit `Run` and `Save and Close`. As you might have guessed, this puts a block on the coordinates `(0, 0, 0)`. The fourth value is the unique identifier for the Grass block to be placed. There is a list of unique ids for each built-in block, but what if we want to place a custom block instead?
21 22
22 23
### Find Block
23 24
[Create a custom block](/wiki/build/how-do-i-make-my-own-custom-blocks), for instance `My Block`. Then replace your previous code with this one:
... ...
@@ -45,19 +46,23 @@ But what if we want to store multiple blocks in our variable?
45 46
46 47
## Arrays
47 48
```js
49
// Create an empty list
48 50
let myBlocks = [];
51
// Store block ids in the list
49 52
myBlocks[0] = findBlock("Bricks");
50 53
myBlocks[1] = findBlock("Dirt");
51 54
```
52
Like previously, we are creating a new variable. But this time, we instead store an empty list `[]` in it. We then add values to the list by assigning them to the indexes in curly braces. This works similar to a [[ List Element ]] block and is also used to access the values afterwards.
55
Like previously, we are creating a new variable. But this time, we instead store an empty list `[]` in it. We then add values to the list by assigning them to the indexes in curly braces. This works similar to a [[List Element]] block and is also used to access the values afterwards.
53 56
```js
57
// Set blocks from the list
54 58
setBlock(0, 0, 1, myBlocks[0]);
55 59
setBlock(1, 0, 1, myBlocks[0]);
56 60
```
57 61
58 62
## Objects
59 63
```js
60
let blockIds = {}
64
let blockIds = {};
65
// Store block ids in the object
61 66
myBlocks["Stone"] = findBlock("Stone");
62 67
myBlocks["Slate"] = findBlock("Slate");
63 68
```
Fancade Wiki