Tabletop Simulator

Tabletop Simulator

Not enough ratings
Counting Bag v2
   
Award
Favorite
Favorited
Unfavorite
File Size
Posted
Updated
117.803 KB
11 Apr, 2018 @ 11:16am
19 Mar, 2021 @ 3:44pm
9 Change Notes ( view )

Subscribe to download
Counting Bag v2

Description
Counting Bag version 2

Can take values from several different places (see Lua script for details), in this order:
1. variable in item's Lua script *state* (i.e. onSave() JSON)
2. variable in name
3. variable in description
4. value listed in the itemValues table in bag's Lua, based on item's name or description
5. variable in item's Lua script *text*
6. total value of item's contents (if any), if item is a deck or bag

The variables are "value", "cost", "price", or "coin", in the format e.g. Value: -341.50.

You can add other variable names if you want. For Lua save state (JSON), it's upper, lower, or title case; for everything else, it's case insensitive.

It knows the specific item values "penny" (1), "nickel" (5), "dime" (10), and "quarter" (25); you can easily add more, just edit the list in the bag's code.

It works with negative and decimal values too, for all of those.

The Counting Bag itself has a value, but it has full recursion, even if the thing you put in isn't a Counting Bag! (Note, however, that it only tries to count the value of stuff inside a container — which includes a deck — if it doesn't first find a value on the container itself.)

It accepts the variable negate_value_if_flipped - or "canasta" by default - which, if set to true, will make the item's value negated if it's flipped over when added to the bag. Thanks to The Manx Turtle for that, and for the custom Canasta deck included in the mod. :-)

It works with stacks and with multiple object drop-in.

All of these variants are demonstrated in the mod's setup. Try it out.



As a bonus, it fixes duplicated GUIDs on entry. This is common if you e.g. get coins from infinite bags, as in the demo here. The new token you pull from the infinite token dispenser has the same GUID every time (blame TTS). This will conflict with the other items already in the bag. This is why it spits them out briefly to re-set the GUID.

The bag has save state, though mainly as a speedup convenience. It will always recalculate the value inside when it's loaded.



Based on:
MrStump's Counting Bowl
Peerless's Finite Bags
MrStump's Memory Bag 2.0
The Manx Turtle's modifications and Canasta deck
28 Comments
Lux 8 Dec, 2023 @ 1:50pm 
anyway i can make it so when the back is locked, it doesnt unlock itself?
SinfulPetGirlRD 15 Jul, 2021 @ 11:33am 
would it be possible to make it display not the total value of everything but instead the total of different items in the bag? so like for D&D you put 10 copper/1 sliver/ 2 electrums/2 gold and 2 platinum coins into the bag, instead of it showing the total value of all that it instead shows 5 numbers, each the total of that specif coin in the bag.
Syke 14 May, 2021 @ 9:19am 
Great Mod.
Came across this when i was locking for a bag, which i could use as a backpack for Tabletop RPG's.

I would second what Lorenzetty said. It would be great if you could set a max value for the counting bag. So if you try to add something which would put it above the max value, it would spit it right back out at a specific place in a radius around the bag.
Kinda like the peerless finite bags but with Item value instead of number of objects.

Use case would be That it would be perfect to use as a Bag of Holding where you have a max. capacity of your backpack and then asign "value" or "weight" to item cards for weapons, armor so players have to pay attention to how much they can carry.
saizai  [author] 19 Mar, 2021 @ 3:36pm 
Updated to disable debugging text (oops) and to demote search of Lua *script* (as opposed to Lua *state*) to last place. Otherwise things just get weird, especially with the Bag itself. Code is not data.
saizai  [author] 19 Mar, 2021 @ 2:59pm 
Updated to fix an issue with counting negative values in description text, and to give better examples in the mod layout and in the Lua text.
saizai  [author] 19 Mar, 2021 @ 2:30pm 
Thanks to @The Manx Turtle and @DLC0234, I've made some major revisions…

1. It now is set by default to accept the variables "value", "cost", "price", or "coin" - lower, upper, or title case, in the name, description, Lua code, or Lua save state. E.g. description "Value: -341.50" works.
2. It knows the values "nickel" (5), "dime" (10), and "quarter" (25).
3. It now works with negative and decimal values, for all fields. (This was a bug before in name/description.)
4. It has full recursion, even if the thing you put in isn't a Counting Bag.
5. It has "canasta mode". ;)
6. It has actually working save state. (Oops. ><)
Rambovi 19 Mar, 2021 @ 11:25am 
@DLC0234 yeah i figured it out before xD Sorry for not sharing it.
Bui its still not possible for Card Descriptions. So i added everything into the code
saizai  [author] 19 Mar, 2021 @ 4:34am 
@The Manx Turtle How did you expand it? I'd like to incorporate whatever you did, so that this is fully flexible.

@Findanniin Just use correct Lua numbers. 0.5 e.g. should work, but .5 probably won't.
saizai  [author] 19 Mar, 2021 @ 4:30am 
@Lorenzetty Hm. I guess so. I'd have to make it spit out items that would make it go over the max value — including ones that it already has, if the max was just added eg, if values change or if items are added via sidebar.

Due to TTS' scripting, I'd have to specify exactly where the ejected items go. I guess the most neutral place to put them would be hovering directly above, since I can't rely on any place around it being clear. Or I'd have to have it have a way to set the ejection site, which is a bit of a pain but doable.

What's the use case you have in mind?
DLC0234 27 Feb, 2021 @ 11:59pm 
@Rambovi I emailed Sai and we figured out that if you set the object's value in the scripting manager as value = -x then it will work! (Example: value = -5)