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

[Responded] Lua loads before player

Discussion in 'User Interface (Including Launcher)' started by Tiina Onir, Nov 17, 2019.

Tags:
Thread Status:
Not open for further replies.
  1. Tiina Onir

    Tiina Onir Avatar

    Messages:
    1,103
    Likes Received:
    1,900
    Trophy Points:
    125
    Location:
    Bramble, South Paladis
    11/17/2019 19:11
    Title: Lua loads before player
    Reproduction Rate: 100%
    Blocker? No
    Details: When logging into the game, Lua loads before your player does. This means calls to get player stats can initially be nil.
    Steps to Reproduce:
    Add the following script to your Lua directory:
    Code:
    function ShroudOnStart()
      ShroudRemovePeriodic("sotadbinfo.UpdateStats")
      sotadbinfoUpdateStats()
      ShroudRegisterPeriodic("sotadbinfo.UpdateStats", "sotadbinfoUpdateStats", 1, true)
      ConsoleLog("OnStart Finished")
    end
    
    function sotadbinfoUpdateStats()
      sotadbinfoHPRatio = ShroudPlayerCurrentHealth/ShroudGetStatValueByNumber(30)
    end
    
    function ShroudOnGUI()
      if sotadbinfoHPRatio < 0.5 then
        ShroudGUILabel(800, 80, 300, 100, "<color=red><size=50>Heal thy self!</size></color>")
      end
    end
    Load game.
    Note repeated errors on Lua console: [Lua]: Lua Error chunk_1:(13,2-33) attempt to compare nil with number
    run "/lua reload"
    Note errors stop.

    User Specs:
    OS: Windows 10 (10.0.0) 64bit
    CPU: Intel(R) Core(TM) i7-8750H CPU @ 2.20GHz (12) System RAM: 32610
    GPU: NVIDIA GeForce GTX 1060 GPU RAM: 6052
    SotA.QA.Win.64.888.Date.11.16.19
    Area: Novia_R6_Hills01_SuperstitionCanyon
    Area Display Name: Superstition Canyon
    Loc: (459.2, 12.4, 368.2)
    Debug: Tm92aWFfUjZfSGlsbHMwMV9TdXBlcnN0aXRpb25DYW55b258fCg0NTkuMTY0LCAxMi40MzUsIDM2OC4yMDQpfCgwLCAtMC45MTgsIDAsIC0wLjM5Nil8MTMzLjM4Mjh8LTEuNjI4NzYyfDYuMDY4NzU4
     
    Merrik and John Markus like this.
  2. Ravalox

    Ravalox Chief Cook and Bottle Washer Moderator SOTA Developer

    Messages:
    1,746
    Likes Received:
    5,003
    Trophy Points:
    125
    Gender:
    Male
    Location:
    Dallas, TX
    May need an "onUserLoad or onUILoad" function to ensure resources are in place...

    Thanks for the report! Created Issue# 66045
     
    Tiina Onir and Merrik like this.
  3. CatweazleX

    CatweazleX Avatar

    Messages:
    653
    Likes Received:
    777
    Trophy Points:
    93
    Location:
    Veritas Sanctuary
    SchroudOnStart only tells that are all scripts loaded. One can use libsota to get an init where everything is available.
    But there should also be a ShroudOnInitComplete() (or so) invoked at a point where people can be sure that all Shroud... values and functions are available.

    Also it would be nice that scripts can be loaded before other scripts are loaded. When scripts depend on other scripts, the dependencies should be loaded first.
    Also this bug needs attention: https://www.shroudoftheavatar.com/f...dic-functions-not-working-as-expected.160237/

    as workaround:
    Code:
    
    -- wrap in ShroudOnStart to be sure all scripts are loaded and libsota is available
    function ShroudOnStart()
    
        -- subscripe to onInit event.
        ui.onInit(function()
    
            lblHealThySelf = ui.label.create(800, 80, 300, 100, "<color=red><size=50>Heal thy self!</size></color>")
    
            setInterval(1, function()
                health = player.health()
                ui.label[lblHealThySelf].visible =  health.current / health.total < 0.5
            end)
    
        end)
    
    end
    
    
    
    -- kill hooks
    function ShroudOnConsoleInput() end
    function ShroudOnGUI() end
    function ShroudOnUpdate() end
    
    [/SPOLER]
     
    Ravalox likes this.
  4. Tiina Onir

    Tiina Onir Avatar

    Messages:
    1,103
    Likes Received:
    1,900
    Trophy Points:
    125
    Location:
    Bramble, South Paladis
    That would be a great fix!

    The workaround that I used was to just set it to "1" in the ShroudOnStart. At least on my client the first periodic happens AFTER the player load, so it's all good. That said, I suspect that leaves a race condition.
     
    Last edited: Nov 20, 2019
    Ravalox likes this.
Thread Status:
Not open for further replies.