Introduction to Editor Scripting
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.
Getting Started
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!
Functions
So let's look at our first example.
// Set block at position (x, y, z) in level or open block
setBlock(x, y, z, prefabIndex);
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.The second line starts with the function
setBlock
. You can imagine this as placing a script block with the aforementioned name. The following text represents the inputs given to this function, separated by ,
and enclosed by brackets. The line is then finished off with a ;
. 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
.
Those inputs were only placeholders, so let's put some values in it!setBlock(0, 0, 0, 3);
### Variables
Unlike most programming languages JS uses a versatile variable declaration this means you can set a variable to any type value casually. JS uses 3 variable declaration key:
• `var` - commonly used variable, is global and can be called anywhere after declaration
• `const` - is a variable that represents a constant value, usually declared before everything
• `let` - is a variable that represents a local variable, its value only persist inside the codeblock `{}` where it is located
Each of this key can represent either `num` value types (`int`, `float`), `tru` types (`bool`), or `String` and can be changed anytime according to the value type it holds. Additionally it can also declare arrays, objects and functions.
### Arrays and Objects
• An array basically acts as a list that is automatically indexed, you can declare an array like this
var listA = ["apple", "orange", true, 100];
var listB = []; listB[0] = "mango"; listB[2] = [0.1, 1]; //outputs ["mango",, [0.1, 1]]
• In the other hand object is an "list of properties" to represent an "object", it works similarly to array but the properties are defined by a name as if it's a variable, you can declare an object like this:
var objA = {
name: "grass",
color: [0, 255, 0],
wilted: false,
leaf: {
type: "pointy",
count: 4
}
}
var objB = {}; objB.something = "something"; //outputs {something: "something"} ```