XenoBot Forums - Powered by vBulletin

User Tag List

Page 1 of 3 123 LastLast
Results 1 to 10 of 22

Thread: Can someone explain Modules a little?

  1. #1
    Senior Member Eion's Avatar
    Join Date
    Dec 2011
    Posts
    558
    Mentioned
    11 Post(s)
    Tagged
    0 Thread(s)

    Can someone explain Modules a little?

    I don't know what a module really does or why you would use it. Could someone explain?

  2. #2
    XenoBot Scripts Developer Syntax's Avatar
    Join Date
    Feb 2011
    Posts
    1,658
    Mentioned
    431 Post(s)
    Tagged
    4 Thread(s)
    It's a queue system. It's so you don't hang up a script's execution running an infinite while loop.
    This way you can have all your scripts in one lua file.

  3. #3

    Join Date
    Feb 2013
    Location
    Sweden
    Posts
    62
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Syntax View Post
    It's a queue system. It's so you don't hang up a script's execution running an infinite while loop.
    This way you can have all your scripts in one lua file.
    So when a module is executed, it will run and finish without having its execution interrupted, compared to a script with an infinite while-loop that can have its execution interrupted whenever?

    I also see some use the registerEventListener(TIMER_TICK, "functionName"), not really sure when this should be used rather than modules

    I've seen in your scripts that you've been using all these different methods. In some you use the above EventListener method, in other you use a module and also
    infinite loop in some scripts. What makes you use different methods? Should modules be used only if you want to concurrently execute different contexts in the same script file?

    Ended up with lots of questions haha, answer them if you feel like

  4. #4
    XenoBot Scripts Developer Syntax's Avatar
    Join Date
    Feb 2011
    Posts
    1,658
    Mentioned
    431 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by Ohman View Post
    So when a module is executed, it will run and finish without having its execution interrupted, compared to a script with an infinite while-loop that can have its execution interrupted whenever?

    I also see some use the registerEventListener(TIMER_TICK, "functionName"), not really sure when this should be used rather than modules

    I've seen in your scripts that you've been using all these different methods. In some you use the above EventListener method, in other you use a module and also
    infinite loop in some scripts. What makes you use different methods? Should modules be used only if you want to concurrently execute different contexts in the same script file?

    Ended up with lots of questions haha, answer them if you feel like
    The main reason to use a module is so the module doesn't get in the way of the rest of the script.
    It allows you for example to display messages in a custom channel while also listening for user input in that said channel.

    registerEventListener(TIMER_TICK... was the old way of achieving this. Modules actually use this method in it's core, but there's a queue system on top of that so you can support
    multiple TIMER_TICKs in a sense, as well as delay, stop, pause, and restart them.

    To support old scripts that still have this method, any registerEventListener with TIMER_TICK specified will create a module, it's the same thing, but you should definitely just use a Module in the first place.

    As far as my scripts, if I had time I would update them all to use modules, infinite while loops are fine if you have a dedicated .lua script for that specific action.

  5. #5
    Erra's Avatar
    Join Date
    Oct 2011
    Location
    Stockholm, Sweden
    Posts
    283
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Syntax View Post
    The main reason to use a module is so the module doesn't get in the way of the rest of the script.
    It allows you for example to display messages in a custom channel while also listening for user input in that said channel.

    registerEventListener(TIMER_TICK... was the old way of achieving this. Modules actually use this method in it's core, but there's a queue system on top of that so you can support
    multiple TIMER_TICKs in a sense, as well as delay, stop, pause, and restart them.

    To support old scripts that still have this method, any registerEventListener with TIMER_TICK specified will create a module, it's the same thing, but you should definitely just use a Module in the first place.

    As far as my scripts, if I had time I would update them all to use modules, infinite while loops are fine if you have a dedicated .lua script for that specific action.
    Sorry to hijack the thread, but have you had a chance to look at the problem I was having with Module.Stop in a custom chat channel?


    New Owner: Kociii



  6. #6

    Join Date
    Jan 2013
    Posts
    20
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Erra View Post
    Sorry to hijack the thread, but have you had a chance to look at the problem I was having with Module.Stop in a custom chat channel?
    I'm having a problem with Module either.

    In my lua file I create:

    PHP Code:
    local EquipRing Module.New('EquipRing', function(module)

    end)

    function 
    onWalkerSelectLabel(label)
       
    EquipRing:IsActive() -- Always returns false
       EquipRing
    :Stop() -- Seems like not to workbecause Module still running
    end 
    Anyone knows why doesn't work?

  7. #7
    Bastiat's Avatar
    Join Date
    Aug 2012
    Location
    Vancouver, BC
    Posts
    44
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Has anyone figured out how to make Module:Stop() work?? I've tried both Module.Stop('module name') and modulename:Stop() formats and it doesn't work...

    The only thing that works is when I create the module without starting it (using false for param 'startOnCreate') I'm able to start the module using Module.Start... But stopping the module afterwards still doesn't work...

    Maybe I'm just fooling myself and I can't use Module.Stop on a label??.. But then again starting a module works...

    Also where should one put module code? In the beginning of the main lua file, the end, a dedicated lua file, or doesn't matter??

  8. #8
    Erra's Avatar
    Join Date
    Oct 2011
    Location
    Stockholm, Sweden
    Posts
    283
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Bastiat View Post
    Has anyone figured out how to make Module:Stop() work?? I've tried both Module.Stop('module name') and modulename:Stop() formats and it doesn't work...

    The only thing that works is when I create the module without starting it (using false for param 'startOnCreate') I'm able to start the module using Module.Start... But stopping the module afterwards still doesn't work...

    Maybe I'm just fooling myself and I can't use Module.Stop on a label??.. But then again starting a module works...

    Also where should one put module code? In the beginning of the main lua file, the end, a dedicated lua file, or doesn't matter??
    We seem to be having the same problem actually! @parrode too


    New Owner: Kociii



  9. #9
    Bastiat's Avatar
    Join Date
    Aug 2012
    Location
    Vancouver, BC
    Posts
    44
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Erra View Post
    We seem to be having the same problem actually! @parrode too
    Yeah I pretty much gave up on modules until things are clearer... For now I'll just keep using multiple lua files. It works, it's reliable, and I can easily manually kill the scripts if I want.

    Honestly I'm not even sure what's the advantage of using modules (other than not having to use multiple lua files)... I thought being able to start and stop modules on labels was a great advantage but it doesn't work. Yes I know I could use labels like lua code:
    elseif (Label == "startRingSwitcher") then RingSwitch = true
    elseif (Label == "stopRingSwitcher") then RingSwitch = false
    and then put if RingSwitch then at the top of the module but I feel it's not clean enough.


    ...Plus I'm not even able to make the anonymous function module format work at all lua code:
    --This format doesn't work (or I just have no idea where the hell to put it):
    Module.New('Ring-Switcher', function()

    --This format works... to some extend:
    function RingSwitcher(module)
    Last edited by Bastiat; 03-18-2013 at 10:10 AM.

  10. #10
    Lifetime Subscriber Hendy's Avatar
    Join Date
    Jan 2012
    Location
    Northern Ireland
    Posts
    1,593
    Mentioned
    7 Post(s)
    Tagged
    1 Thread(s)
    Below is a description of modules, explanation from @Spectrus

    Code:
    A module is a function that when created, is added to the TIMER_TICK event. It is then executed every 200ms, as is the behavior of the TIMER_TICK. 
    
    To create a Module, simply call the constructor for it: Module.New(name, func). The parameter name is a string which can then be used to modify the status of the module (i.e. Module.Stop(name), etc.). The function is the function that will be called when the TIMER_TICK event occurs.
    
    In essence, a module is as simple as this:
    
    ###############################
    
    -- First create a function for your module.
    function checkCreature()
       local c = Creature.New('Demon')
       if c:isAlive() and c:isOnScreen() then
          print('Run!')
       end
    end
    
    -- Then create a module for that function.
    Module.New('creature check', checkCreature)
    
    ################################
    
    If you would like to control your module at any time, you can start or stop it with Module.Start(name) and Module.Stop(name).

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •