Getting load error on just ConsoleLog

Discussion in 'Lua Discussions' started by Toular, Nov 16, 2019.

Tags:
Thread Status:
Not open for further replies.
  1. Toular

    Toular Avatar

    Messages:
    661
    Likes Received:
    631
    Trophy Points:
    93
    Ok, I have something strange going on here ...

    A nearly empty lua file that simply calls ConsoleLog give me a load error.

    I use cygwin on Windows 10, so that's why the following looks like Linux:
    xxxxxx@localhost~/Shroud of the Avatar(QA)/Lua
    $ cat odometer.lua
    ConsoleLog( "Initializing" )

    xxxxxx@localhost~/Shroud of the Avatar(QA)/Lua
    $ tail -4 ../ChatLogs/SotAChatLog_Dutaurm\ Teroue_2019-11-16.txt
    [11/16/2019 4:15:21 PM] (Lua): Error loading file C:\Users\xxxxxx\AppData\Roaming\Portalarium\Shroud of the Avatar(QA)\Lua\odometer.lua chunk_1:(6,0-36): attempt to call a nil value
    [11/16/2019 4:17:36 PM] (Lua): Error loading file C:\Users\xxxxxx\AppData\Roaming\Portalarium\Shroud of the Avatar(QA)\Lua\odometer.lua chunk_1:(1,10-28): attempt to call a nil value
    [11/16/2019 4:20:03 PM] You are already performing another action.
    [11/16/2019 4:21:18 PM] (Lua): Error loading file C:\Users\xxxxxx\AppData\Roaming\Portalarium\Shroud of the Avatar(QA)\Lua\odometer.lua chunk_1:(1,10-28): attempt to call a nil value

    xxxxxx@localhost~/Shroud of the Avatar(QA)/Lua


    It's behaving as if "ConsoleLog" is not defined. I've tried changing that to "ShroudConsoleLog", just in case there was a change I didn't see announced.



    Note: "odometer.lua" is supposed to be a more accurate implementation of what Chris was doing on his twitch stream a few days ago.
     
  2. DavidDC

    DavidDC Programmer Moderator SOTA Developer

    Messages:
    1,532
    Likes Received:
    3,236
    Trophy Points:
    113
    Gender:
    Male
    That shouldnt be called outside of a function. Also make sure to just have 1 file in that folder, having many right now cause error
     
  3. DavidDC

    DavidDC Programmer Moderator SOTA Developer

    Messages:
    1,532
    Likes Received:
    3,236
    Trophy Points:
    113
    Gender:
    Male
    Here a working example:

    Code:
    local test
    
    function ShroudOnStart()
        test = "hello world"
        myfunction2()
    end
    
    function myfunction2()
        ConsoleLog(string.format("%s",test))
    end
     
  4. Toular

    Toular Avatar

    Messages:
    661
    Likes Received:
    631
    Trophy Points:
    93
    I thought I saw something in one of Atos' twitch streams about ShroudOnStart .. But, in the google doc I don't see it.

    That was it. Thanks. Just so it's "out there" ... here's what "odometer" looks like. The distance traveled is just to the right of the compass
    function ShroudOnGUI()
    odometer.totalDistanceTraveled = odometer.totalDistanceTraveled
    + ( ( odometer.prevX - ShroudPlayerX ) ^ 2
    + ( odometer.prevY - ShroudPlayerY ) ^ 2
    + ( odometer.prevZ - ShroudPlayerZ ) ^ 2 ) ^ 0.5;

    odometer.prevX = ShroudPlayerX;
    odometer.prevY = ShroudPlayerY;
    odometer.prevZ = ShroudPlayerZ;

    message = string.format( "Traveled %10.2f", odometer.totalDistanceTraveled );

    ShroudGUILabel( 2 * ShroudGetScreenX() / 3, 5, 200, 20, message );
    end

    odometer = { }

    function ShroudOnStart()
    ConsoleLog( "Initializing odometer" )

    odometer.prevX = ShroudPlayerX
    odometer.prevY = ShroudPlayerY
    odometer.prevZ = ShroudPlayerZ

    odometer.totalDistanceTraveled = 0

    ConsoleLog( "Odometer initialized" )
    end
     
  5. CatweazleX

    CatweazleX Avatar

    Messages:
    653
    Likes Received:
    777
    Trophy Points:
    93
    Location:
    Veritas Sanctuary
    Currently you have to "implment" all the ShroudOn.. functions in every script you have in the folder. To avoid the error. You can leave them empty if not used, but they need to be there.
    Code:
    -- kill hooks
    function ShroudOnConsoleInput() end
    function ShroudOnGUI() end
    function ShroudOnUpdate() end
    function ShroudOnStart() end
    
     
  6. Toular

    Toular Avatar

    Messages:
    661
    Likes Received:
    631
    Trophy Points:
    93
    It's working fine without implementing ShroudOnConsoleInput or ShroudOnUpdate. Maybe today's QA patch removed that requirement?
     
  7. DavidDC

    DavidDC Programmer Moderator SOTA Developer

    Messages:
    1,532
    Likes Received:
    3,236
    Trophy Points:
    113
    Gender:
    Male
    Its a bug related to order of file loaded.

    Lets say you got file a.lua and file b.lua. If you have ShroudOnConsoleInput in a.lua and not in b.lua, when game will load those script, the second one will overrride the first one, so your input wont work anymore in a.lua. But if its in b.lua, and not in a.lua, its gonna work, cause b got loaded the last.
     
  8. Toular

    Toular Avatar

    Messages:
    661
    Likes Received:
    631
    Trophy Points:
    93
    Hmmm ... Ok ... Although, I do actually have a second script that is working also. It does not implement ShroudOnConsoleInput or ShroudOnUpdate either, so that must be why it's working. So, I'm basically making use of a benign bug. Guess I'll stick empty event handlers in there... Seems a waste of CPU cycles to do nothing, but ... OK.
     
  9. CatweazleX

    CatweazleX Avatar

    Messages:
    653
    Likes Received:
    777
    Trophy Points:
    93
    Location:
    Veritas Sanctuary
    As i observed it it will not overwritten, but ShroudOnConsoleInput will be executed 2 times in a.lua because b.lua has not implmented it.
    So, ShroudOnUpdate is not implmented in odomoeter but if there is another script that uses ShroudOnUpdate it will become it twice (or more often, depending on how many files are loaded in which order and how many have implemented it).
    Anyway, that is a bug and need to be fixed.

    ADD:

    This bug is still active in QA888:
    https://www.shroudoftheavatar.com/f...-not-working-as-expected.160237/#post-1266353

    it tested it with the following three files:
    Code:
    -- file1.lua
    function ShroudOnStart()
        ShroudConsoleLog("Init file1")
    end
    
    -- file2.lua
    function ShroudOnStart()
        ShroudConsoleLog("Init file2")
    end
    
    -- file3.lua
    --[[function ShroudOnStart()
        ShroudConsoleLog("Init file3")
    end]]
    
    ShroudOnStart is executed twice in either file1 or file2 because file3 has not implmented it. When the code in file3 is commented in, all files executed fine.
     
    Last edited: Nov 17, 2019
Thread Status:
Not open for further replies.