Dismiss Notice
This Section is READ ONLY - All Posts Are Archived

[Responded] Lua periodic functions not working as expected

Discussion in 'Critical Issues (Blockers, Performance, Crashes)' started by Feldon Grimshaw, Nov 15, 2019.

Thread Status:
Not open for further replies.
  1. Feldon Grimshaw

    Feldon Grimshaw Avatar

    Messages:
    257
    Likes Received:
    448
    Trophy Points:
    28
    This is on QA build 886. (released early this morning).

    I expected 'calling aPeriodic, one time' to be called one time, but it was called twice.

    I expected 'calling bPeriodic' to be called 5 times, but it was only called once.

    [​IMG]

    Here's the code for a.lua:
    Code:
    function ShroudOnStart()
        ConsoleLog('starting A')
    
        local periodRateInS = 5.0
        local repeatPeriodcA = false
        ShroudRegisterPeriodic('a_periodic', 'aPeriodic', periodRateInS, repeatPeriodcA)
    end
    
    function aPeriodic()
        ConsoleLog('calling aPeriodic, one time. should be 5 seconds after onStart')
    end
    Here's the c ode for b.lua:
    Code:
    _remainingCallsToB = 5
    
    function ShroudOnStart()
        ConsoleLog('starting B')
    
        local periodRateInS = 3.0
        local repeatPeriodcB = true
        ShroudRegisterPeriodic('b_periodic', 'bPeriodic', periodRateInS, repeatPeriodcB)
    end
    
    function bPeriodic()
        _remainingCallsToB = _remainingCallsToB - 1
        ConsoleLog('calling bPeriodic. remaining calls: ' .. _remainingCallsToB)
    
        if _remainingCallsToB == 0 then
            ConsoleLog('stopping call to b_periodic')
            ShroudRemovePeriodic('b_periodic')
        end
    end
     
  2. CatweazleX

    CatweazleX Avatar

    Messages:
    653
    Likes Received:
    777
    Trophy Points:
    93
    Location:
    Veritas Sanctuary
  3. CatweazleX

    CatweazleX Avatar

    Messages:
    653
    Likes Received:
    777
    Trophy Points:
    93
    Location:
    Veritas Sanctuary
    All ShroudOn... functions are called as often as files are loaded. If there are 3 .lua files loaded ShroudOn.. functions are called 3 times.
    If a lua script does not implement a ShroudOn.. function it is called in the script that last implmented it, instead.
    The Same is true for the ShroudPeriodic called function(s).

    Code:
    -- file1.lua:
    ConsoleLog("file1")
    
    ShroudRegisterPeriodic("", "ptest", 5, true)
    function ptest()
    ConsoleLog("ptest in file1")
    end
    
    -- file2.lua
    ConsoleLog("file2")
    
    function ptest()
    ConsoleLog("ptest in file2")
    end
    
    -- file3.lua
    ConsoleLog("file3")
    
    
    ptest is called 3 times (3 files). It is called in file1 then file2 and then file2 again, because file3 doeas not implment ptest and file2 was the last known file that implmented it, so the function from file2 is used instead.
    This can be avoided by implementing _all_ functions that are called by shroud as empty functions (all ShroudOn... and invoked by ShroudPeriodic). Eg.: function ShroudOnGUI() end. So the function is found and not called somewhere else instead.

    The ShroudOn... and the periodic function shouldn't called for every script. They should called only once!

    (Use something like ShroudRegisterHandler(string handler, callback handler_func, mixed userdata); And the registered handler is only called once in the script that has it registered. Even another script contains a function with the same name)
    Code:
    -- file1.lua
    function file1GuiDrawHandler(mixed userdata)
    -- draw something
    end
    function file1PeriodicHandler(mixed UserData)
    -- do something
    end
    
    ShroudRegisterHandler("onGUI", file1GuiDrawHandler, nil)
    ShroudRegisterPeriodic("myName", file1PeriodicHandler, count, once, myUserData)
    
     
    Last edited: Nov 15, 2019
    Feldon Grimshaw and Jaesun like this.
  4. Ravalox

    Ravalox Chief Cook and Bottle Washer Moderator SOTA Developer

    Messages:
    1,731
    Likes Received:
    4,954
    Trophy Points:
    125
    Gender:
    Male
    Location:
    Dallas, TX
    Created issue# 66052
     
Thread Status:
Not open for further replies.