Results 1 to 2 of 2

Thread: obj.reload() is sometimes leaving a copy of the old version of the object?

  1. #1

    obj.reload() is sometimes leaving a copy of the old version of the object?

    Hi there... I have a small script that changes a object as it is moved around through script zones. The idea is that the player board has a "fetch card" button that changes each time someone moves their pawn. I have everything working, but there is one issue I can not work out why it is happening. I think it has something to do with spawn frames and stuff.

    Basically occasionally, not all the time, when obj.reload happens, the object spawns a new copy with the new textures but leaves the old object behind on the table.

    if darwButton.getDescription() ~= area then
        local changedDrawButton = darwButton.reload()
        if darwButton ~= nil then destroyObject(darwButton) end
    I tried putting a IF statement to look for the old object and destroy it but it does not seem to work either.
    Any ideas on why this is doing it .. and if so... any solutions.

    : EXAMPLE :

    As you can see, as I move around the player token on the board, the button on the player area (bottom left) changes. Clicking on it will draw the appropriate card for that board position. But as I move the token around sometimes, after a while, when the object changes, it leaves behind a copy of the original.

  2. #2
    Work Around Solution
    (does not address the problem, only avoids it)

    I have a solution that seems to have fixed this.. but it is not addressing the error, just avoiding it.
    The script I wrote works by objects moving into script zones I have set at each map location, as it enters it checks the token name to see if it is a active player, and then changes the location button as shown in the video above.

    What I have done is simply used a "timer wait function" code that I use a lot in TTS to only trigger functions after a function is triggered for the last time.

    function TimmerChangeDraw(zone, obj)
        local prams = {z=zone, o=obj}
            identifier="Time_functionName"..obj.getGUID(), delay=0.8,
            function_name="functionName", function_owner=self, parameters = prams
    Basically this is it. Instead of a function being called each time it enters a zone it instead calls this timer code. What it does is simply start a timer that last 0.8 seconds. When the timer finishes it then runs a function. The trick is that in the timer code at the start it also destroys the timer. So what this means is that everytime the timer is function is called it destroys the existing timer if it is there and starts a new one that lasts for 0.8 seconds. The upshot of this is that no matter how many times the timer function is called in quick succession the actual function I want to trigger is only called once.

    You can use this method for all sorts of cool things like counting bowls, card draws and other stuff.

    By using this code so the reload() thing is done only once when the icon has stopped moving through the map zones, has (or so it seems) completely bypassed the error. Which I am certain was occurring, when reload() was being called on a object that had not fully spawned, as the reference exists before the spawn is completed. Meaning if I moved the token to fast through the map zones, it would try to change a mid spawning object and this somehow makes the copies.. (I think)

Similar Threads

  1. reload() after SetCustomObject causing error
    By decumanusmaximus in forum Scripting
    Replies: 3
    Last Post: 10-12-2018, 03:09 PM
  2. How do you place a copy of an object?
    By Raldor in forum Scripting
    Replies: 2
    Last Post: 04-25-2017, 10:40 PM
  3. object.reload()
    By TattleTale in forum Scripting
    Replies: 0
    Last Post: 02-06-2017, 05:09 PM
  4. Leaving Custom Tile bottom image intentionally blank?
    By Mark in forum General Discussion
    Replies: 2
    Last Post: 01-31-2017, 08:45 AM
  5. Card Leaving A Hand Face Down
    By LordAshes in forum Scripting
    Replies: 6
    Last Post: 07-26-2016, 04: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