vault backup: 2025-03-25 10:42:16
All checks were successful
Update pages on webserver / Update (push) Successful in 5s
All checks were successful
Update pages on webserver / Update (push) Successful in 5s
This commit is contained in:
parent
d4d0488b91
commit
723cb5723c
@ -38,7 +38,7 @@ In mcfunction, this is not so straightforward. Macros would make this really cle
|
|||||||
```vb
|
```vb
|
||||||
function test_namespace:search_array {keyword: "entry500"}
|
function test_namespace:search_array {keyword: "entry500"}
|
||||||
```
|
```
|
||||||
Unfortunately, macros come with a performance hit. A more performant method, albeit less elegant, is to store the keyword in NBT storage prior to calling the function. The storage can be removed after the function is run:
|
Unfortunately, macros come with a performance hit. In this particular situation, we can bypass macros altogether. While it's less elegant, it is more performant to store the keyword in NBT storage prior to calling the function. The storage can be removed after the function is run:
|
||||||
```vb
|
```vb
|
||||||
data modify storage test_namespace:test_namespace temp.keyword set value 'entry500'
|
data modify storage test_namespace:test_namespace temp.keyword set value 'entry500'
|
||||||
function test_namespace:search_array
|
function test_namespace:search_array
|
||||||
@ -47,7 +47,7 @@ data remove storage test_namespace:test_namespace temp.keyword
|
|||||||
```
|
```
|
||||||
Once the entry is found, it is stored in the `temp.result` storage, which can then be consumed by another function.
|
Once the entry is found, it is stored in the `temp.result` storage, which can then be consumed by another function.
|
||||||
|
|
||||||
Now for the logic to do the actual array searching...
|
Now for the logic to do the actual array searching. Here, the performance hit of running macros is worth it as the alternative involves a massive number of commands to manually iterate over an array. As we'll see later when benchmarking functions, manual iteration is *really* slow.
|
||||||
# one macro
|
# one macro
|
||||||
Macros allow us to reach into our array and pick out an entry that matching value in the `string` property. This is something that I didn't realize (for some reason) and was pointed out by **PuckiSilver** and **amandin** on the Datapack Hub discord server.
|
Macros allow us to reach into our array and pick out an entry that matching value in the `string` property. This is something that I didn't realize (for some reason) and was pointed out by **PuckiSilver** and **amandin** on the Datapack Hub discord server.
|
||||||
```vb
|
```vb
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user