isuckatcode-pages/Minecraft Datapacking/When Two Macros are Faster than One.md
themodernhakr eaa623c413
All checks were successful
Update pages on webserver / Update (push) Successful in 6s
vault backup: 2025-03-24 14:10:08
2025-03-24 14:10:08 -05:00

53 lines
1.6 KiB
Markdown

---
title: When Two Macros are Faster than One
published: "true"
---
While working on my Database datapack (still WIP), I knew I'd want to find
# One Macro
```ts
// 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
```
```ts
// one_macro/_searcharray.mcfunction
$data modify storage test_namespace:test_namespace temp.result set from storage`` test_namespace:test_namespace database.test.arrayTest3.array[string:$(keyword)]
```
# Two Macro
```ts
// 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
```
```ts
// two_macro/_searchindex.mcfunction
$data modify storage test_namespace:test_namespace temp.index set from storage test_namespace:test_namespace database.test.arrayTest2.index.$(keyword)
```
```ts
// two_macro/_searcharray.mcfunction
$data modify storage test_namespace:test_namespace temp.result set from storage test_namespace:test_namespace database.test.arrayTest2.array[$(index)]
```