Using Storage as a Log
I'm trying to store info from gameplay into a log using storage. I'm having trouble finding a good way to do so. Example of what I'm trying to do: Say I have a server shop that you can sell items too, and I want to log every time a player sells something. Just for this example, I'll say there's only three things to track --gametime, amount of money received (reward), and the item type. Here's an example NBT output:
} Root:{ Log:[ {gametime:329598,item:"minecraft:diamond",reward:40}, {gametime:329547,item:"minecraft:diamond",reward:10}, {gametime:329262,item:"minecraft:diamond",reward:10} ], Pool:{ gametime:329598,reward:40 } } }Here is what code I have so far:
## POOL execute store result storage se:telemetry Root.Pool.gametime int 1 run time query gametime execute store result storage se:telemetry Root.Pool.reward int 1 run scoreboard players get $yield sell ## Update Log # Prepend a template to the Log list. This is so every time this is run, there will always be a new template at index 0. data modify storage se:telemetry Root.Log prepend value {gametime: -1, reward: -1, item: ""} # Copy Pool.gametime into Log[0].gametime data modify storage se:telemetry Root.Log[0].gametime set from storage se:telemetry Root.Pool.gametime # Copy Pool.reward into Log[0].reward data modify storage se:telemetry Root.Log[0].reward set from storage se:telemetry Root.Pool.reward # Store item id. Pool value not needed because you can add directly from entity! data modify storage se:telemetry Root.Log.[0].item set from entity @s SelectedItem.idAs you can see I am storing the values to a pool, and then storing them into the log. The log stores a new instance with new info every time a player sells something. The way I'm doing it works, but it seems a little over complicated. Is there a better way to do this?