Results 1 to 2 of 2

Thread: Help with strange bug in my code!

  1. #1

    Help with strange bug in my code!

    Hi there... am I totally stuck on an error I have with my code and I can not for the life of me work out how to fix it. I have tried rebuilding the entire tool 4 times.. each with a different method and nothing works.. I think I have tracked down the problem.. but as far as I know.. it shouldn't be a problem so I have no idea how to fix it.

    The Situation

    • I have a bag of 27 card, each named.
    • I loop through the bag, and add to a table data form the cards found inside the bag. The GUID goes in as the key and the NAME goes in as the value


    The Problem

    This makes a a table of 26....
    Code:
        for k, v in ipairs(getBag('player').getObjects()) do
            bag_Deck[v.guid] = '???'
        end

    The resulting table is ALWAYS 26 instead of 27 in length.


    Code:
        local bag_Deck = {}
        for k, v in ipairs(getBag('player').getObjects()) do
            table.insert(bag_Deck, v.guid)
        end

    The resulting table is ALWAYS 27 in length.

    I am getting length by....

    Code:
    function varLength(v)
        local count = 0
        for k, v in pairs(v) do
            count = count + 1
        end
        return count
    end
    print(varLength(bag_Deck))
    The bag itself has 27 items in it.
    Last edited by Tragic; 04-22-2018 at 01:15 AM.
    My Boardgame uTube chan - Tragic's Table Top
    BGG Guild of BoardGame uTubers - Tube Tables

  2. #2
    Apparently one of the card GUIDs in the bag is a duplicate. Try
    Code:
    for k, v in ipairs(getBag('player').getObjects()) do
        if not bag_Deck[v.guid] then
            bag_Deck[v.guid] = '???'
        else
            print('!!! DUPLICATE: ' .. v.guid)
        end
    end
    That's why (as I said the 8946th time) I avoid GUIDs like fire whenever possible. You can do without them, really, pretty much could be used just for onSave/onLoad and simple getObjectFromGUIDs for initialization. They can screw you over hard and there are *numerous* bugs with GUIDs especially when spawning/cloning shit.

Similar Threads

  1. Strange problem in ATOM?
    By Tragic in forum Scripting
    Replies: 11
    Last Post: 05-29-2018, 01:47 PM
  2. Strange model issue with tint...
    By MarcusRaven in forum General Discussion
    Replies: 2
    Last Post: 04-11-2018, 07:00 AM
  3. Strange bug with custom tile colliders
    By Spheniscine in forum Bug Reports
    Replies: 1
    Last Post: 06-10-2017, 12:21 AM
  4. [SOLVED] Infinite bags are acting strange!!!
    By Tumba in forum Bug Reports
    Replies: 2
    Last Post: 06-09-2017, 04:20 PM
  5. Replies: 4
    Last Post: 04-26-2017, 05:51 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
  •