Complete handler for object:to() in Lua

  • #1, by trepnWednesday, 20. December 2017, 18:15 6 years ago
    I'm trying to fadeout my inventory interface and set its visibility to false when done. I am able to fade out but then the buttons stay active on the invisible interface so I need to hide it completely. Is there a onComplete handler or something to achieve this?


    function Main.hideInventory()
      if inventoryOpen == true then
        local inventory = getObject("Interfaces[inventory]")
        inventory:to(inventoryTransitionDuration, {InterfaceVisibility = 0})
        -- this needs to be done in oncomplete
        -- inventory.InterfaceVisible = false
        inventoryOpen = false
      end
    end


    Newbie

    60 Posts


  • #2, by afrlmeWednesday, 20. December 2017, 18:31 6 years ago
    Probably best to add that line inside of an execute a script action part inside of a called by other action block.

    create a called by other action block somewhere, then add this to them...

    pause for value "example" duration
    execute a script >

    Interfaces["inventory"].InterfaceVisible = false
    inventoryOpen = false


    "example" woud be a vs value that you stored the fade time inside of. Anyway, rename the called by other action block to something like "hide_inventory".

    Now edit your function script to call the called by other action you have created...
    function Main.hideInventory()
      if inventoryOpen == true then
        local inventory = Interfaces["inventory"]
        inventory:to(inventoryTransitionDuration, {InterfaceVisibility = 0})
        startAction(Actions["hide_inventory"]) -- call the called by other action that handles when to hide the inventory
      end
    end

    Imperator

    7278 Posts

  • #3, by SimonSWednesday, 20. December 2017, 18:33 6 years ago
    There is no onComplete handler, but there is a setDelay:

    function Main.hideInventory()
    
      if inventoryOpen == true then
    
        local inventory = getObject("Interfaces[inventory]")
    
        inventory:to(inventoryTransitionDuration, {InterfaceVisibility = 0})
    
        -- this needs to be done in oncomplete
    
        setDelay(inventoryTransitionDuration, function()
           inventory.InterfaceVisible = false
        end)
    
        inventoryOpen = false
    
      end
    
    end

    Thread Captain

    1580 Posts

  • #4, by trepnThursday, 21. December 2017, 10:43 6 years ago
    Tnx both of you. @AFRLme I prefer to keep everything in the code instead of adding another action part. So setDelay it is. I don't see anywhere in the documentation that it is possible to cancel a setDelay, are there any options for doing this?  You might want to cancel a delayed method to be excecuted when a user action like show menu or something pops up.

    Newbie

    60 Posts

  • #5, by afrlmeThursday, 21. December 2017, 13:19 6 years ago
    I don't think you can cancel it, but you could wrap the code inside of the function in an if query. Maybe you could query if the current scene is not the menu or if a condition/value does not equal x. Should do the trick.

    setDelay(inventoryTransitionDuration, function()
     if not Conditions["example"].ConditionValue then
       inventory.InterfaceVisible = false
     end
    end)

    Imperator

    7278 Posts

  • #6, by trepnThursday, 21. December 2017, 15:05 6 years ago
    Tnx!

    Newbie

    60 Posts