In the mean time, I need to figure out how to count the number of items crafted.
This is the meta right now with Bread and Dough as placeholders:
An attempt at human readable formatting:
Bread / Sets recipe ingredients as variables, calls CraftLoop state
Always
All:
- ExprAct setvar{use, Baking Pan], ExprAct setvar{on, Dough]
- Call: Craftloop, return to: CraftLoopReturn
Expr getobjectinternaltype[wobjectfindininventorybyname[getvar[use]]]==7&&getobjectinternaltype[wobjectfindininventorybyname[getvar[on]]]==7
ExprAct actiontryapplyitem[wobjectfindininventorybyname[getvar[use]], wobjectfindininventorybyname[getvar[on]]]
CraftLoop / If ingredients are missing, sets meta state for missing item
getobjectinternaltype[wobjectfindininventorybyname[getvar[use]]]!=7
All:
- ExprAct setvar[need, getvar[use]]
- ExprChat \/vt setmetastate +getvar[need]
All:
- ExprAct setvar[need, getvar[on]]
- ExprChat \/vt setmetastate +getvar[need]
All:
- Second in state >= 2
- Expr getobjectinternaltype[wobjectfindininventorybyname[getvar[need]]]==7
CraftLoopReturn / Transition rule from called state to original recipe state. Allows returning to a state from a call using a variable
Always
ExprChat \/vt setmetastate +getvar[capturegroup_item]
Default / Listener. Supports the !make and !reset commands.
ChatMessageCapture ^(\[[A-z]+?\] |)You (say|says|tells you), \"!make (?<amount>[0-9]*) (?<item>.*)\"$
All:
- ExprAct setvar[capturegroup_amount, cnumber[getvar[capturegroup_amount]]]
- ExprAct \/vt setmetastate +getvar[capturegroup_item]
All:
- ExprAct setvar[capturegroup_amount, 0]
- ExprAct clearvar[capturegroup_item]
- Set Meta State: Default
So this works, currently, to make bread with just flour, water, and a baking pan in your inventory. I have write some logic to gracefully error when a base component or tool is missing.
Currently it just loops infinitely until it runs out of base components then resets to default. I would like it to loop until it has made capturegroup_amount of capturegroup_item.
My first idea was to use a InventoryItemCount condition. Can't use variables. Would require a rule for every single item with hard coded names and amounts.
Second idea was a countdown in the CraftLoop state. Every run would do capturegroup_amount-1. However that would run on every item, including dependencies.
Third idea was a ChatMessageCapture watching for item names in chat, but the success messages vary from item to item too much and I can't use a variable in a ChatMessageCapture. Most of my problems seem to stem from not being able to use variables outside of expressions which is why this meta is just expression bukakke.
Fourth idea was a countdown in the recipe rule itself. However the way the loop works it doesn't craft an item every time because of dependencies. It could loop through the recipe rule multiple times before it actually crafts something. One idea is addin to capturegroup_amount when a dependency is crafted and subtracting whenever the capturegroup_item rule is run but I don't quite have my mind wrapped around how to do that yet.
Any suggestions on how to solve this counting issue? It would be easier if there was a way to count items with a meta expression but I don't see any method do actually get an item count, just information about the item itself.