From 008e8a4ef210405f0b20694716066ef62fc8fbe7 Mon Sep 17 00:00:00 2001 From: themodernhakr Date: Mon, 24 Mar 2025 23:04:56 -0500 Subject: [PATCH] vault backup: 2025-03-24 23:04:56 --- .obsidian/workspace.json | 6 +++--- .../When Two Macros are Faster than One.md | 17 ++++++++++------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/.obsidian/workspace.json b/.obsidian/workspace.json index 19e3320..632a0ae 100644 --- a/.obsidian/workspace.json +++ b/.obsidian/workspace.json @@ -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", diff --git a/Minecraft Datapacking/When Two Macros are Faster than One.md b/Minecraft Datapacking/When Two Macros are Faster than One.md index a5c8196..9759ec0 100644 --- a/Minecraft Datapacking/When Two Macros are Faster than One.md +++ b/Minecraft Datapacking/When Two Macros are Faster than One.md @@ -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