Login

Fancade Wiki

Updated Introduction to Editor Scripting.md (markdown)

... ...
@@ -97,27 +97,30 @@ methods are special properties of an object that can be used as instruction for
97 97
98 98
```js
99 99
let justATree = {
100
x: 0,
100
x: 1,
101 101
y: 0,
102
z: 0,
102
z: 1,
103 103
components: {
104 104
// component: material, size, position
105
trunk: [8 /*Wood Y*/, [1, 6, 1] [0, 0, 0]],
106
leaves: [495 /*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, 3, -1]]
107 107
},
108
build: () => {
109
for (let c in this.components) {
110
for (let i = 0; i < (c[1][0] * c[1][1] * c[1][2]); i++) {
111
let x = c[2][0] + (i % c[1][0]);
112
let y = c[2][1] + (i % c[1][1]);
113
let z = c[2][2] + (i % c[1][2]);
108
build: function() {
109
for (let e in this.components) {
110
let c = this.components;
111
for (let i = 0; i < (c[e][1][0] * c[e][1][1] * c[e][1][2]); i++) {
112
let x = c[e][2][0] + (i % c[e][1][0]);
113
let y = c[e][2][1] + ((i/c[e][1][0]) % c[e][1][1]);
114
let z = c[e][2][2] + (((i/c[e][1][0])/c[e][1][1]) % c[e][1][2]);
114 115
// The "this" keyword refers to the object it is inside to,
115 116
// We use "this" when the object is not or not yet defined by a variable
116
setBlock(this.x + x, this.y + y, this.z + z, c[0]);
117
setBlock(this.x + x, this.y + y, this.z + z, c[e][0]);
117 118
}
118 119
}
119 120
}
120 121
}
122
123
justATree.build();
121 124
```
122 125
123 126
Fancade Wiki