Results 1 to 8 of 8

Thread: How do I easily move tokens from a bag to another?

  1. #1

    How do I easily move tokens from a bag to another?

    Game has two bags - both hold the same kind of tokens. If expansion is used, the expansion adds more tokens, and they're randomly drawn from the bag, so they must be mixed together. What is the easiest way to do this?

    Currently I did this by first making a table of the contents of the expansion bag, since it's only 12 items it was a reasonable effort - it holds the name and the guid for each token inside. Then, when the user clicks a button, I spawn the tokens one by one from the expansion bag, over the base game bag, where they then fall in. I had to put a 20 frame delay (maybe works with less, haven't tested yet) for them to not collide mid air.

    As I said, it does work and suffices for now, but is there another way that I'm unaware of?

  2. #2
    I do not know of a way to do that. It might be easier if a function to put something in a bag (instead of having to place it above) gets implemented but even then I doubt you will be able to move items over to the other bag without them flying around.

    Maybe it is possible for you to spawn new tokens using [URL="http://berserk-games.com/knowledgebase/api/"]spawnObject[/URL] instead of taking them from a bag? I had a similar requirement where I needed a bag of randomized tokens with the amount of tokens depending on the number of players.
    I just generate a LUA table with the tokens needed, randomize it and then I spawn all the tokens in random order above the bag and let them fall in, no need for delays and it works just fine even when I spawn more than 80 objects. It is just important to spawn them apart from each other (add some to the Y-axis for each item).

    My suggestions:
    a) Try using takeObject to take the tokens from the expansion bag and position all items over the base game bag but with an offset for each item (e.g Position Item 1: X=0.0, Y=2.0, Z=0.0, Item 2: X=0.0,Y=2.3,Z=0.0,...). If that failes, try doing the same but use the callback of takeObject to lock the item when it is in position. When all tokens are spawned, unlock all of them at the same time.
    or:
    b) Instead of moving tokens from bag to bag simply spawn new token objects above the base game bag.

  3. #3
    Stacking the tokens above the target bag as suggested by Huffel works and there's no yield loops needed at all. To find out the vertical offset needed, I piled a few tokens in a staggered pattern so they wouldn't auto-stack. Waited for an autosave, then edited the autosave.json file to look at the 'y' values for the piled tokens. Added a bit extra and used it as the 'y' value delta for each iteration of the takeObject loop.

  4. #4
    Join Date
    May 2016
    Posts
    1,072
    I wrote a script in the workshop that demonstrates how to put items into bags. Using that bit of code, you can combine it the command to pull objects out of a different bag and, basically, drop it into your main bag.

    [url]http://steamcommunity.com/sharedfiles/filedetails/?id=716724531[/url]

    Hope it helps.

  5. #5
    Instead of getting the GUIDs of all the tokens in the bag, I suggest you can use description. For example, all your tokens in the bag use the key word "Token" in the description. In addition, if desired, the description can also contain the name of the expansion or base set so that, if needed, you can identify that later. Then you can write a loop that will collect all the GUIDs based on that. This method is really nice because if someone adds another expansion later, as long as they properly fill in the description attribute, your code will automatically include the expansion (because you are determining the GUIDs at runtime instead of hard-coding them).

  6. #6
    Join Date
    May 2016
    Posts
    1,072
    Once an item is in a bag, the only 3 elements you can obtain for it are its name, guid and the index number representing its place in the bag. Items placed into bags are "destroyed" and no longer part of the sim until re spawned by removing them. So for moving items from one bag to another it would not work.

    But in general, yes working with descriptions or names is always much simpler

  7. #7
    Quote Originally Posted by MrStump View Post
    Once an item is in a bag, the only 3 elements you can obtain for it are its name, guid and the index number representing its place in the bag. Items placed into bags are "destroyed" and no longer part of the sim until re spawned by removing them. So for moving items from one bag to another it would not work.

    But in general, yes working with descriptions or names is always much simpler
    Sorry, maybe I was not clear. You would get the GUIDs of all drawn cards (i.e. those that have been removed). Yes, until a card is drawn it does not exist and thus you can't get description.

  8. #8
    Thanks for the input. I took the route Huffel suggested, and it cut down the setup time dramatically (had to wait 30 frames after each token earlier, now they're all spawned immediately).

    These forums are great! So helpful people around

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •