[BUG?] misleading addEvent error message

  • This is the original "bug" report, but as it turns out I was calling addEvent with an nil function.


    While playing around with writing a "modmanager" to clean-up my nasty script, I ran into a bit-wall.


    I am implementing a manager object which other objects (mods) can attach to.
    The manager automatically calls addEvent for any event functions in the mod(s) object when it is attached.


    When I run the server, enable is flipped before addEvent's are called *and* before onEnable is called.


    Code
    [LUA]Script "h0tmod" loaded. Author: h0tw1r3 Team: ClarkMania
    [LUA][h0tmod] 01/02/15 19:35:09.096: ModManager: init mod manager (does nothing yet)
    [LUA][h0tmod] 01/02/15 19:35:09.099: Test: attach begin
    [LUA][h0tmod] 01/02/15 19:35:09.099: Test: register begin
    [LUA][h0tmod] addEvent is only allowed before "onEnable" is called.
    [LUA][h0tmod] 01/02/15 19:35:09.1: ModManager: hook failed: InventoryToChest
    [LUA][h0tmod] 01/02/15 19:35:09.101: Test: register end
    [LUA][h0tmod] 01/02/15 19:35:09.102: Test: attach end
    [LUA][h0tmod] 01/02/15 19:35:09.102: onEnable begin
    [LUA][h0tmod] 01/02/15 19:35:09.103: onEnable end


    Script as tested.


    Not sure why, but I think java LuaScript.enabled is set before lua onEnable is actually invoked.


    I've added print statements everywhere. Code seems to be processed in the correct order.


    Does LuaScript "this.script.call()" return immediately after parsing or something? I'm baffled. 8|

  • It is not a bug, it is intended behaviour (for technical reasons) to not being able to add events during runtime ;) In your particular case, it should work to move the ModManager:list() out of the onEnable() body?

  • I understand that just before onEnable (lua) is invoked, enabled is set to true (java) which prevents addEvent (lua) from being called again. No problem there.


    The events are added before the onEvent lua function is even invoked. It happens at mod:attach(ModManager). I could break out IntelliJ and debug the java, but I figured I would ask first.


    Removing ModManager:list() had no effect.

  • Nevermind! Very sorry for the noise.


    Turns out to be the error message is misleading.


    I had a typo in the function name to the addEvent call. Once that was fixed the event was added correctly.

  • Nevermind! Very sorry for the noise.


    Turns out to be the error message is misleading.


    I had a typo in the function name to the addEvent call. Once that was fixed the event was added correctly.


    Found out exactly the same right now :D We changed the error message, it will now give proper information if eventname is not a string or if the function is nil (this was happening in this case) ;)
    Thanks for pointing that out!

Participate now!

Don’t have an account yet? Create a new account now and be part of our community!