Login

Fancade Wiki

Updated Introduction to Editor Scripting.md (markdown)

... ...
@@ -62,7 +62,7 @@ setBlock(1, 0, 1, myBlocks[0]);
62 62
## Loops
63 63
Now if we want to place multiple blocks at once of course we will need a loop! JS uses 3 types of loop; "while" loop, "do while" loop and "for" loop. In this scenario we will use the "for" loop.
64 64
```js
65
const myBlocks = [findBlock("Bricks"), findBlock("Dirt")];
65
const myBlocks = [1, 2, 3]; // Stone, Brick, Grass
66 66
67 67
let x = 0;
68 68
for (let element of myBlocks) {
... ...
@@ -82,8 +82,8 @@ let justATree = {
82 82
z: 0,
83 83
components: {
84 84
// component: material, size, position
85
trunk: ["Wood Y", [1, 6, 1] [0, 0, 0]],
86
leaves: [Foliage, [3, 3, 3], [-1, 4, -1]]
85
trunk: [8 /*Wood Y*/, [1, 6, 1] [0, 0, 0]],
86
leaves: [495 /*Foliage*/, [3, 3, 3], [-1, 4, -1]]
87 87
}
88 88
};
89 89
... ...
@@ -102,8 +102,8 @@ let justATree = {
102 102
z: 0,
103 103
components: {
104 104
// component: material, size, position
105
trunk: ["Wood Y", [1, 6, 1] [0, 0, 0]],
106
leaves: ["Foliage", [3, 3, 3], [-1, 4, -1]]
105
trunk: [8 /*Wood Y*/, [1, 6, 1] [0, 0, 0]],
106
leaves: [495 /*Foliage*/, [3, 3, 3], [-1, 4, -1]]
107 107
},
108 108
build: () => {
109 109
for (let c in this.components) {
... ...
@@ -111,8 +111,8 @@ let justATree = {
111 111
let x = c[2][0] + (i % c[1][0]);
112 112
let y = c[2][1] + (i % c[1][1]);
113 113
let z = c[2][2] + (i % c[1][2]);
114
// the "this" keyword refers to the object it is inside to,
115
// we use "this" when the object is not or not yet defined by a variable
114
// The "this" keyword refers to the object it is inside to,
115
// We use "this" when the object is not or not yet defined by a variable
116 116
setBlock(this.x + x, this.y + y, this.z + z, c[0]);
117 117
}
118 118
}
Fancade Wiki