#Looking for help with Bagged items

1 messages · Page 1 of 1 (latest)

dire oracle
#

Discussion post: https://steamcommunity.com/app/286160/discussions/3/3763355214779357007/

TL;DR is that I have some chips, that have custom names and descriptions.

  • Calling the .name attribute returns the custom name correctly. (custom name)
  • Doing the same when done on a stack of custom chips also works correctly. (ChipStack)
    -Calling the .name attribute on a stack of custom chips within a bag, does not work correctly (returns the custom_name)

It seems there is no real way of getting that ChipStack value once the custom stack is in a bag. Normal chip stacks in a bag return "ChipStack" as well, so I know this is how I'm supposed to get that name.

Not 100% sure if this is a bug or intentional, but it would seem that the following finding occurs: item type, .name attr , .getName() non-bagged, "Chip_1000", Err: attempt to call a nil value bagged, "Chip 1000", nothing/nil, Err: attempt to call a nil value I understand the nil answers, but it seems that theres two different name for the chip ...

feral carbon
dire oracle
#

hey rheza! Unfortunately, that is not the case for this instance

#

.getName() on the bagged, custom, stack of chips results in an error thrown for calling a nil value

dire oracle
#

In fact, calling .getName on any bagged chip (custom name and description or not) causes a calling a nil value error

#

I dumped the full table for a custom chipstack and it doesn't have the ChipStack value anywhere like it does outside of the bag. I smell something wonky

#

The last line is the error upon calling getName() on the object (custom chip) within the bag

wispy ibex
#

Take a look at log(bag_item) You need to discover the format of those entries. At a guess it is effectively contained_items.

#

That is, a table of serialized objects.

#

chipstack value would be calculated on the fly.

mossy cobalt
#

Reading everyhting in that post and this thread it's still unclear to me what you actually want or are trying to get to

dire oracle
mossy cobalt
#

Just save the bag and you're done right?

dire oracle
#

Is that feasible for any number of players?

mossy cobalt
#

Sure, why not?

dire oracle
#

Originally I was going to serialize it into a json string and stash it in gm notes

mossy cobalt
#

most poker tables just plunk all players bags into a large bag.

dire oracle
#

How do they accurately load the bags then?

#

Change the indices from numbers to player names?

#

I’ll take a peak at the saving components of the api

dire oracle
#

Can't seem to find any ways to call a save function on an object, am I missing something?

dire oracle
# feral carbon https://discord.com/channels/342471570955960324/368208369812504587/9925052808794...

This is sort of what I figured was going on, however, it still begs the question why the standard chipstack has its internal .name correct as ChipStack, but the customized chipstack instead uses the individual component's custom name. For example, a deck of custom-named cards, when in deck form, doesn't have a special name at all, and remains being called as a Deck, why is this different for chips?

feral carbon
#

I'm guessing you're mixing up where you are accessing the .name attribute. There are only two cases that could happen:

A. On an actual object (custom chip / custom model, chip stack / custom model stack, or objects in the table you retrieve from getObjects on a zone, etc): it will return the internal resource name, which should probably match the "type" listed here: https://api.tabletopsimulator.com/built-in-object/. This value is the Internal Resource Name probably used to refer to the Unity object templates etc; as indicated in the API documentation, most of the time / generally you don't need it unless you are specifying the type parameter for the spawnObject functions. Note that this string values might be different than the object's type attribute.
B. On an object description table in the table you retrieved from getObjects() on a container (bag/deck; refer to the discord message I linked above for more explanations): what you are doing is accessing the name entry in the returned object description table. The keys to that table are defined in the function definition of getObjects() and has nothing to do with the TTS object attributes. It will return the custom_name nickname attribute which would be the same with what you get from getName().

I don't think there is any other variations to these. Unfortunately, it seems like TTS dev has a strong stand in backward compatibility, so it is very unlikely that future updates will attempt to adjust this to prevent confusions (e.g. by changing the attribute name to resource_name/resource_type or the key name for the getObjects, or separate the getObjects() function on containers to getContentDescriptions(), etc). If you see quirky behaviours/API, it's usually to minimalize the impact to legacy/existing scripts.

mossy cobalt
dire oracle
dire oracle
mossy cobalt
#

I don;t understand what you mean.

dire oracle
#

there is no code equivalent to do save an object that I could find

#

Obviously I can save game state, but I would rather be saving the objects themselves or their data held so that players may selectively save/load without affecting the entire game

mossy cobalt
dire oracle
#

??

mossy cobalt
#

every object is saved when you save the game. What do you want to trigger

dire oracle
#

I dont want to save all objects

#

I just want to save an individual

mossy cobalt
#

as in, put it in saved objects?

dire oracle
#

sure, or somehow getting a serialized string version

#

either or

mossy cobalt
#

for what purpose?

#

Because there is quite a difference

dire oracle
#

namely, so players can save and load their bags

#

as I stated

mossy cobalt
#

You want players to save their own bag?

dire oracle
#

correct

#

so they may selectively save and load

mossy cobalt
#

let them right-click it and save it

dire oracle
#

thats not pragmatic

#

which is the goal

#

appreciate the work arounds but would like to stick to the subject and intent

mossy cobalt
#

you cannot store something on the users machine. So no, you cannot make a savedobject for a user.
The usual way this works for most poker tables it's storing their bag in a larger bag with their steam id as identifier.
Then scripting things to put it in or retreiving it.
What you want seems improbably

dire oracle
#

What I want, is to be able to get the name of the stack of chips properly

#

within the bag

#

the means to do so work when the custom named stack is outside of the bag, or the stack does not have a custom name and is in the bag

#

im uploading a demo mod shortly which will hopefully be more illustrative than I can be with my words haha

mossy cobalt
#

getObjects().nickname?

dire oracle
#

no

#

one sec the demo code is almost done

mossy cobalt
#

secs are a relative term aparently 😄

dire oracle
#

Was busy with work and am out with friends now

#

You can test it on your own if you’d like, try to get a stack of chips that have the same custom name to read out chip stack when checking their name or whatever attribute

#

When in a bag

dire oracle
#

alright i have demo code uploaded now - feel free to play around with it

#

So to recap: how the hell do you tell the difference between a stack of custom named chips and a singular custom named chip within a bag

wispy ibex
#

UM, you remember what you are looking into? There is no rule for how an object is represented internally. So, if you are looking in a bag, use the format for the bag. If you are looking at a stack not in a bag, use another format. Yes you can probably figure it out by looking at the data, I often do that, but that is a matter of hunt and poke. You are deep inside the works of TTS, which was (IMO) invented, not designed.

feral carbon
mossy cobalt
#
function onChat(message, player)
  single = getObjectFromGUID("ea4a15")
  stack = getObjectFromGUID("cbfda1")
  print("[ff0000]Single[-]")
  print(logString(single.getData().ContainedObjects))
  print("[ff0000]Stack[-]")
  print(logString(stack.getData().ContainedObjects))
end

getObjects() does indeed not differentiate the two.
The point still though is why would you want this, because from what you said there should be no reason to know that at all

dire oracle
dire oracle
#

I believe the distinguisher is that custom named chips, when stacked, maintain the custom name, rather than flipping back to a default chipstack like a deck of cards does

#

this same exact scenario is not a problem for a deck of custom named cards

mossy cobalt
#

check my example if you must

dire oracle
#

will do!

#

This may be a good work around actually

dire oracle
#

You're a fucking rockstar @mossy cobalt this works exactly as I need it - I wasn't fully aware of what getData() could do, this allows me to serialize the bag and its content as a json string into a GM-visible notebook tab, allowing me to spawn in the bag and its contents based off steam ids upon onPlayerLoad

mossy cobalt
#

getJSON() would've worked too then...

#

Still not needed, but whatever. I'm leaving this thread