Results 1 to 8 of 8

Thread: Tables are grouping like objects together

  1. #1

    Tables are grouping like objects together

    Hullo!

    So there is this game where there are tiles, I need to get a specific subset of them, shuffle them, and lay them out on the table.

    Each tile CAN be unique, or MAY be in a stack of tiles. I take the each tile stack, shuffle, and draw one, OR I just take the unique tile. I do this for a few different tiles, to make a table.

    However, when I iterate through the table Lua is grouping any tiles that might come from the same stack into one 'object'.

    So instead of getting TileIce1, TileIce2, TileFire, I get TileIceStack, TileFire.

    How to I stop the table from grouping the like objects together?
    Code:
    function setTiles()
        print("getting tiles")
        tiles = { getTile(iceId), getTile(iceId), getTile(fireId)}
    
        --this is shuffle function that does work on the table
        tiles = shuffle(tiles)
    
         TILE_WIDTH = 2.7
      -- the size of the tiles table comes back as 2, not 3
        for i = 1, #tiles do
           xpos = i * TILE_WIDTH
           tiles[i].setPosition(Vector((xpos-2.7) , 0 , 4.6))
        end
    end
    
    
    
    function getTile(id)
      tileStack = getObjectFromGUID(id)
    
      if pcall(tileStack.shuffle()) then
        t = tileStack.takeObject()
      else
        -- tile is single
        t = tileStack
      end
    
      t.setPosition(Vector(0,0,0))
      return t
    end
    Thanks in advance

  2. #2
    Ok, so i debugged some more, and it seems that tileStack.takeObject is taking ALL the objects. tileStack.shuffle() never throws an error to pcall() even if there is nothing to shuffle (only one tile).

  3. #3
    Ok, I realize at this point I'm just having a conversation with myself, so this is just a very public rubber ducking. REGARDLESS.

    So I think I don't know how to properly call the .takeObject() method, the .. is it a lambda it takes as the parameter, I don't know where to look for the docs on that. The official API doesn't exactly spell it out?

    Help on how I find that?

  4. #4
    https://api.tabletopsimulator.com/object/#takeobject

    Seems pretty clear to me... you pass it a table. Pay attention to the tip in the API: the object reference can't really be used until the object has finished spawning, which requires a callback or wait.

    Also, .getQuantity() returns the number of objects in a stack, or -1 if the object is not a stack. So use that instead of .shuffle() to figure out if its a stack.
    Last edited by jotakami; 08-01-2020 at 12:20 PM.

  5. #5
    Join Date
    Sep 2017
    Posts
    397
    As AufDerWelt said, use getQuantity to determine whether you have a stack, the key issue is that in getTile you separate the tiles using takeObject, but then move them to {0,0,0} where they will immediately recombine into a stack! You must keep their positions separate to prevent that. One approach is to shuffle the id list and loop through it calling getTile(id, loopIndex) and position accordingly. Note that your table surface is at about 1, not 0, so your final placement is putting the tiles below the surface. (Some table surfaces are higher than that, but a surface at or below 0, will cause serious problems with the physics simulation.)

  6. #6
    Quote Originally Posted by jotakami View Post
    https://api.tabletopsimulator.com/object/#takeobject

    Seems pretty clear to me... you pass it a table. Pay attention to the tip in the API: the object reference can't really be used until the object has finished spawning, which requires a callback or wait.

    Also, .getQuantity() returns the number of objects in a stack, or -1 if the object is not a stack. So use that instead of .shuffle() to figure out if its a stack.
    THANKS, I don't know why I couldn't find this in the API!
    And great getQuantity() tips, thanks again!

    - - - Updated - - -

    Quote Originally Posted by cche View Post
    As AufDerWelt said, use getQuantity to determine whether you have a stack, the key issue is that in getTile you separate the tiles using takeObject, but then move them to {0,0,0} where they will immediately recombine into a stack! You must keep their positions separate to prevent that. One approach is to shuffle the id list and loop through it calling getTile(id, loopIndex) and position accordingly. Note that your table surface is at about 1, not 0, so your final placement is putting the tiles below the surface. (Some table surfaces are higher than that, but a surface at or below 0, will cause serious problems with the physics simulation.)
    All good ideas, I'll try them, ty!

  7. #7
    So for anyone in the future, this is what I came up with, to determine if it's just a single or mini stack, thanks to jotakami and cche!
    Code:
    function getTile(id)
      tileStack = getObjectFromGUID(id)
    
      if tileStack.getQuantity() != -1 then
        tileStack.shuffle()
        t = tileStack.takeObject()
      else
        t = tileStack
      end
    
      t.flip()
      t.setPosition(Vector(-30, 1, 21))
      return t
    end

  8. #8
    Join Date
    Sep 2017
    Posts
    397
    Remember that if two tiles of the same type are together they will become a deck again. the setPosition in getTile() needs to have a variable value or the gotten tile must be moved again before the next tile is placed in that fixed position.

Similar Threads

  1. Game Keys ordering and grouping
    By Unreal_Ed in forum Scripting
    Replies: 0
    Last Post: 05-10-2020, 02:39 PM
  2. Deck Manipulation 3 (Grouping Cards)
    By fredsdc in forum Suggestions
    Replies: 3
    Last Post: 06-01-2017, 03:10 PM
  3. [ADDED] Grouping items / putObject
    By Huffel in forum Scripting Suggestions
    Replies: 3
    Last Post: 02-20-2017, 10:39 AM
  4. Ghost objects when grouping
    By Skorpion9x in forum Scripting
    Replies: 0
    Last Post: 08-26-2016, 09:50 AM
  5. [SOLVED] Unintentional Grouping
    By inkBot in forum Technical Support
    Replies: 2
    Last Post: 08-17-2015, 05:30 PM

Posting Permissions

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