Results 1 to 4 of 4

Thread: reload() after SetCustomObject causing error

  1. #1

    Angry reload() after SetCustomObject causing error

    Here's the script:

    Code:
    function onPlayerChangedColor(vPlayer_Color)
        tPlayers = Player.getPlayers()
        oSetupBoard.setCustomObject({ image = tSetupBoards[#tPlayers] })
        oSetupBoard.reload()
    end
    This code does what its supposed to (i.e. when a player changes color, it switches the image on a custom board depending on the number of players) but it generates the following error:

    Error in Script (Global) function <onPlayerChangedColor>:<Unknown Error>

    It only occurs when the reload() is called (i.e. if I comment out oSetupBoard.reload(), no error occurs but then I don't see the new board image).

    Any ideas?

    P.S. tSetupBoards is a table of URLs numerically indexed to the number of players

  2. #2
    Check if your oSetupBoard is a ref to the correct object

    Check if tSetupBoards[#tPlayers] is a valid link

    Try adding rest of params to setCustomObject or do
    Code:
    local custom = oSetupBoard.getCustomObject()
    custom.image = oSetupBoard[#tPlayers]
    oSetupBoard.setCustomObject(custom)
    oSetupBoard.reload()

  3. #3
    Thanks dzikakulka. Here's my amended code that works:

    Code:
    function onPlayerChangedColor(vPlayer_Color)
        oSetupBoard = getObjectFromGUID(vSetupBoard_GUID)
        tPlayers = Player.getPlayers()
        if bSetup then
            local oCustom = oSetupBoard.getCustomObject()
            oCustom.image = tSetupBoards[#tPlayers]
            oSetupBoard.setCustomObject(oCustom)
            oSetupBoard.reload()
        end
    end
    I was defining the GUID and getObjectFromGUID in OnLoad() but, when the reload is run for onPlayerChangedColor, it creates a new object reference so I need to recreate the reference before doing the reload.

    I'm also trying to test the following which may work as well:

    Code:
    oSetupBoard = oSetupBoard.reload()
    Do you ever have times with Atom where you send script updates (Ctrl-Shift-S) & it sends but Tabletop Simulator doesn't receive it? I'll have it work for a while & then it stops working. Right now, I can reload Atom & TTS, Atom receives the files but it won't send them correctly. It is driving me nuts! Any ideas on that?

    UPDATE: oSetupBoard = oSetupBoard.reload() works as well. I had to logoff my computer, login, load Atom then TTS & I can send script updates to TTS again (until it stops working again) ...
    Last edited by decumanusmaximus; 10-12-2018 at 09:55 AM.

  4. #4
    Yeah, obj.reload() returns the new ref so if you have e.g. a global variable that needs to point to it, assigning result of reload() to it is the way to go.

    For Atom plugin problems, there's a pinned feedback topic on Scripting forum here, I guess some logs would be useful for that (but I'm not really familiar with Atom).

Similar Threads

  1. Forced reload of images without restarting TTS?
    By Pluisjen in forum General Discussion
    Replies: 6
    Last Post: 10-26-2017, 02:50 PM
  2. Reset/Reload Game Through Script?
    By chillblain in forum Scripting
    Replies: 1
    Last Post: 08-09-2017, 09:52 PM
  3. object.reload()
    By TattleTale in forum Scripting
    Replies: 0
    Last Post: 02-06-2017, 05:09 PM
  4. Force custom assets to reload for all clients
    By Waggles in forum Suggestions
    Replies: 2
    Last Post: 06-11-2015, 06:49 PM
  5. [Suggestion] Image Reload Feature
    By wsmccall in forum General Discussion
    Replies: 3
    Last Post: 06-18-2014, 02:13 AM

Posting Permissions

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