vault backup: 2025-03-24 23:04:56
All checks were successful
Update pages on webserver / Update (push) Successful in 5s

This commit is contained in:
themodernhakr 2025-03-24 23:04:56 -05:00
parent 2fb9fb3e36
commit 008e8a4ef2
2 changed files with 13 additions and 10 deletions

View File

@ -13,12 +13,12 @@
"state": {
"type": "markdown",
"state": {
"file": "Minecraft Datapacking/When Two Macros are Faster than One.md",
"file": "Minecraft Datapacking/When Two Macros are Faster Than One.md",
"mode": "source",
"source": false
},
"icon": "lucide-file",
"title": "When Two Macros are Faster than One"
"title": "When Two Macros are Faster Than One"
}
}
]
@ -183,7 +183,7 @@
"lastOpenFiles": [
"Minecraft Server Administration/Tips for Minecraft Server Administration.md",
"Minecraft Server Administration/index.md",
"Minecraft Datapacking/When Two Macros are Faster than One.md",
"Minecraft Datapacking/When Two Macros are Faster Than One.md",
"Minecraft Datapacking/Arrays",
"Minecraft Datapacking",
"index.md",

View File

@ -1,11 +1,11 @@
---
title: When Two Macros are Faster than One
title: when two macros are faster than one
draft: "false"
---
While working on my Database datapack (still WIP), I knew I'd want to find
# Scenario
## Dataset
# scenario
## dataset
The data is stored in a storage `#_macro.array`. Array is populated with a total of 500 entries, each having `id` and `string` fields.
```json
[
@ -20,8 +20,10 @@ The data is stored in a storage `#_macro.array`. Array is populated with a total
}
]
```
## Constraints
The objective is to create an interface that receives a keyword, say `entry500`, and searches `#_macro.array` for an entry where the value of `string` matches the keyword. The keyword
## constraints
The objective is to create an interface that receives a keyword, say `entry500`, and searches `#_macro.array` for an entry where the value of `string` matches the keyword.
The keyword must be able to be entered by a player at runtime, and `#_macro.array` can have an arbitrary number of custom entries created by a player.
In TypeScript, it would look something like this:
```ts
@ -32,7 +34,8 @@ function searchArray(keyword: string) {
searchArray('entry500')
```
# One Macro
In mcfunction, this is not so easy. We *could* use macros
# one macro
Macros allow us to reach into our array and pick out an entry that matching value in the `string` property.
```vb
... one_macro.array[string:$(keyword)]
@ -54,7 +57,7 @@ data remove storage test_namespace:test_namespace temp.result
$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
```vb
'# two_macro/run.mcfunction