Updated Introduction to Editor Scripting.md (markdown)
commited
commit
26fdcd34e03aa68eb074761955d82b22ee01619d
... | ... | @@ -72,12 +72,33 @@ let justATree = { |
72 | 72 | trunk: ["Wood Y", [1, 6, 1] [0, 0, 0]], |
73 | 73 | leaves: [Foliage, [3, 3, 3], [-1, 4, -1]] |
74 | 74 | } |
75 | } |
|
75 | }; |
|
76 | ||
77 | //If you want to you can also add or override properties later |
|
76 | 78 | ``` |
77 | properties are values that represent chracteristics of an object it can be any value type or a function. As you can see in our example we made the `justATree` object
|
|
79 | properties are values that represent chracteristics of an object it can be any value type or a function. As you can see in our example we made the object `justATree`which contains properties named `position` and `component`. Using this properties lets try to make a method that will build the tree!
|
|
78 | 80 | |
79 | 81 | ### Methods |
80 | methods are special properties of an object that can be used as instruction for its behaviors |
|
82 | methods are special properties of an object that can be used as instruction for its behaviors. Now lets try to add a new method named `build` inside `justATree`. |
|
83 | ||
84 | ``` |
|
85 | let justATree = { |
|
86 | position: [0, 0, 0], |
|
87 | components: { |
|
88 | // component: material, size, position |
|
89 | trunk: ["Wood Y", [1, 6, 1] [0, 0, 0]], |
|
90 | leaves: [Foliage, [3, 3, 3], [-1, 4, -1]] |
|
91 | }, |
|
92 | build: () => { |
|
93 | // the "this" keyword refers to the object it is inside to, in this case the "justATree" |
|
94 | let x = this.position[0]; |
|
95 | let y = this.position[1]; |
|
96 | let z = this.position[2]; |
|
97 | ||
98 | setBlock(x, y, z, 0); |
|
99 | } |
|
100 | } |
|
101 | ``` |
|
81 | 102 | |
82 | 103 | ## Loops |
83 | 104 |