Results 1 to 8 of 8

Thread: Spawn object completion

  1. #1
    Join Date
    May 2017
    Location
    Rocklin, CA
    Posts
    80

    Spawn object completion

    When I spawn a new token object that has an image, sometimes it takes a little time for the image to load and display properly on the token.
    I would like to spawn this new token out of site under the table, and when it has fully loaded its image, move it into position above the table.
    Is there any way to know when a newly spawned object is fully loaded with its image?
    Currently, I move the object above the table in the callback function specified in the spawn object parameters.
    But a lot of the times, the image is still loading when this move occurs.
    Some computers are faster than others and this time can vary depending on the computer speed.
    Is there a way to know when this process is complete before moving the token above the table?
    Thanks for any advice.

  2. #2
    Quote Originally Posted by Ajkiger1 View Post
    When I spawn a new token object that has an image, sometimes it takes a little time for the image to load and display properly on the token.
    I would like to spawn this new token out of site under the table, and when it has fully loaded its image, move it into position above the table.
    Is there any way to know when a newly spawned object is fully loaded with its image?
    Currently, I move the object above the table in the callback function specified in the spawn object parameters.
    But a lot of the times, the image is still loading when this move occurs.
    Some computers are faster than others and this time can vary depending on the computer speed.
    Is there a way to know when this process is complete before moving the token above the table?
    Thanks for any advice.
    What you need is to supply a callback function to your function call.
    https://api.tabletopsimulator.com/base/#spawnobject

    Code:
     parameters.callback_function: The function to activate after the Object has finished spawning into the scene.
    Optional, defaults to not being used.
    A reference to the object spawned is always passed to callback_function. See the example for how to access it.

  3. #3
    Join Date
    May 2017
    Location
    Rocklin, CA
    Posts
    80
    Well, yes, I do that. Apparently, loading an image for an object is a completely separate and independent action from instantiating the object itself.
    I guess the only work around is to use a timer - not ideal, but it gets the job done.

  4. #4
    There's "obj.spawning" and "obj.loading_custom" fields, you might want to check if those are changed when it finishes loading. Still, loading for host may take different amount of time than for other clients.

  5. #5
    Join Date
    May 2017
    Location
    Rocklin, CA
    Posts
    80
    Thanks, those look like promising avenues to explore.
    Iíll let you know if I have any success with them.

  6. #6
    Join Date
    May 2017
    Location
    Rocklin, CA
    Posts
    80
    "obj.loading_custom" works like a champ.
    Boolean value that is true when image is loading and changes to false when image fully loaded.
    Used a coroutine with a while loop to execute it.
    Thanks for the insight.

  7. #7
    PS. You can just use Wait like

    Code:
    local obj = spawnObject(stuff)
    Wait.condition(function()
        print('Done!')
    end,
    function() return not obj.loading_custom end)

  8. #8
    Join Date
    May 2017
    Location
    Rocklin, CA
    Posts
    80
    That Wait is pretty cool

Similar Threads

  1. Replies: 1
    Last Post: 07-03-2018, 07:52 AM
  2. Spawn Specific Domino
    By Phase in forum Scripting
    Replies: 0
    Last Post: 04-14-2018, 06:52 PM
  3. [SUPPORT] Unable to do anything after attempting to spawn saved object in MP
    By Tippex in forum Technical Support
    Replies: 6
    Last Post: 03-20-2018, 08:56 PM
  4. Spawn object callback parameters
    By Ajkiger1 in forum Scripting
    Replies: 3
    Last Post: 06-25-2017, 05:46 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
  •