All checks were successful
Update pages on webserver / Update (push) Successful in 5s
1.8 KiB
1.8 KiB
| title | draft |
|---|---|
| When Two Macros are Faster than One | false |
While working on my Database datapack (still WIP), I knew I'd want to find
Scenario
Dataset
[
{
id: 1,
string: "entry1"
},
...
{
id: 500,
string: "entry500"
}
]
Constraints
One Macro
Macros allow us to reach into our array and pick out an entry that matching value in the string property.
> one_macro.array[string:$(keyword)]
-- one_macro/run.mcfunction
data modify storage test_namespace:test_namespace temp.keyword set value 'entry500'
function test_namespace:one_macro/_searcharray with storage test_namespace:test_namespace temp
data remove storage test_namespace:test_namespace temp.keyword
data remove storage test_namespace:test_namespace temp.result
-- one_macro/_searcharray.mcfunction
$data modify storage test_namespace:test_namespace temp.result set from storage test_namespace:test_namespace one_macro.array[string:$(keyword)]
Two Macro
' two_macro/run.mcfunction
data modify storage test_namespace:test_namespace temp.keyword set value 'entry500'
function test_namespace:two_macro/_searchindex with storage test_namespace:test_namespace temp
function test_namespace:two_macro/_searcharray with storage test_namespace:test_namespace temp
data remove storage test_namespace:test_namespace temp.keyword
data remove storage test_namespace:test_namespace temp.index
data remove storage test_namespace:test_namespace temp.result
' two_macro/_searchindex.mcfunction
$data modify storage test_namespace:test_namespace temp.index set from storage test_namespace:test_namespace two_macro.index.$(keyword)
' two_macro/_searcharray.mcfunction
$data modify storage test_namespace:test_namespace temp.result set from storage test_namespace:test_namespace two_macro.array[$(index)]