Loop function Broken in M8 2.9?
  • Invisible Ray
    member
    Posts: 33
    Joined: Mon May 16, 2011 11:50 pm

    Loop function Broken in M8 2.9?

    by Invisible Ray » Wed Sep 23, 2015 10:09 pm

    I am running Modul8 v2.9 and Python 2.6.7.

    I discovered that the loop function repeats unexpectedly.

    Very simple test script, on Init():
    for i in range(5):
    print 'i = ', i

    This is the output:
    i = 0
    i = 1
    i = 2
    i = 3
    i = 4
    i = 0
    i = 1
    i = 2
    i = 3
    i = 4
  • Invisible Ray
    member
    Posts: 33
    Joined: Mon May 16, 2011 11:50 pm

    Re: Loop function Broken in M8 2.9?

    by Invisible Ray » Thu Sep 24, 2015 4:04 pm

    OK, just determined that this only happens on restart of the module.

    If you make a button and attach the loop to the button via MessageEvent, it only iterates once.

    Also, if you leave the loop code in the init handler, it will repeat the loop on restart, but if you use the pause and start buttons on the module, it only iterates once.

    Another little undocumented quirk.

    I really wish someone would make a scripting FAQ to cover all of this undocumented behavior.
  • anomad
    master
    Posts: 411
    Joined: Sun Oct 21, 2007 10:07 pm
    Location: north cakalacky, usa
    Contact:

    Re: Loop function Broken in M8 2.9?

    by anomad » Thu Sep 24, 2015 7:14 pm

    . i don't know why Init() only being run when the module is started or restarted (via CMD-SHIFT-R) would be considered a quirk…


    -james
    (a nomad. )
  • Invisible Ray
    member
    Posts: 33
    Joined: Mon May 16, 2011 11:50 pm

    Re: Loop function Broken in M8 2.9?

    by Invisible Ray » Mon Oct 05, 2015 9:23 pm

    The problem isn't that Init() runs. The problem is that when the loop function is put in the Init() module, it runs through the specified number of iterations twice. When it is called by a button in the MessageEvent() module, it only runs through the specified number of iterations once, the way it is supposed to.

    The behavior is clearly documented in my original post and response.
  • anomad
    master
    Posts: 411
    Joined: Sun Oct 21, 2007 10:07 pm
    Location: north cakalacky, usa
    Contact:

    Re: Loop function Broken in M8 2.9?

    by anomad » Mon Oct 05, 2015 10:34 pm

    . interesting.

    . i created a new module

    . in Init()

    Code: Select all

    print "start test"

    for i in range(5):
       print i
       
    print "end test"


    . when the module is activated, I see :

    start test
    0
    1
    2
    3
    4
    end test

    . which leads me to believe that it only executed the loop once

    . it appears when I re-load (CMD-SHIFT-R) but that makes sense b/c Init() is being run again.

    . is your loop inside of a function or object?


    -james
    (a nomad. )
  • Invisible Ray
    member
    Posts: 33
    Joined: Mon May 16, 2011 11:50 pm

    Re: Loop function Broken in M8 2.9?

    by Invisible Ray » Tue Oct 27, 2015 2:56 pm

    I tested your code and it works as expected on module restart. I need to review my own looping function to see why it doesn't work like that.

    Thanks.
  • Cbnxxd
    junior Member
    Posts: 2
    Joined: Fri Nov 20, 2015 9:22 am

    Re: Loop function Broken in M8 2.9?

    by Cbnxxd » Fri Nov 20, 2015 9:32 am

    hahaha this thread is too good.coquegsm
    Last edited by Cbnxxd on Thu Nov 26, 2015 9:46 am, edited 2 times in total.
  • Invisible Ray
    member
    Posts: 33
    Joined: Mon May 16, 2011 11:50 pm

    Re: Loop function Broken in M8 2.9?

    by Invisible Ray » Fri Nov 20, 2015 6:59 pm

    Thanks for your sarcasm. It's super helpful.

    Just in case you care about the actual issue here; I raised this thread because I noticed bizarre behavior on the Init() script section. Anything I write in that section which generates an output (like a print statement) is repeated on my system. anomad said that the behavior does not happen on his system, so I assumed there was some kind of problem with my own system.

    Something is still not right in the Init() section, and I just proved it using anomad's example script.

    If I quit and relaunch Modul8, when I launch a module for the first time, it behaves as expected. Each statement in the Init() section is executed once. If I stop a module and relaunch it, using (option)+(command)+R, each statement in the Init() section executes twice. I just demonstrated it with a nomad's example code. The only way to get statements to execute once is to quit and relaunch Modul8 again.

    Can anyone explain this behavior? Or do you want to just make fun of people?
  • anomad
    master
    Posts: 411
    Joined: Sun Oct 21, 2007 10:07 pm
    Location: north cakalacky, usa
    Contact:

    Re: Loop function Broken in M8 2.9?

    by anomad » Fri Nov 20, 2015 9:45 pm

    . hmmmm.

    . i didn't see that you were reloading from a paused/stopped state.

    . i can recreate Init() running twice. when the module is 'paused' and then, instead of pressing the 'play' button - pressing CMD-SHIFT-R it does run my loop twice… confirming what you stated in your initial observation.

    . i haven't seen that before since i usually put my own 'active/inactive' button in my modules, rather than start/stop them via the Modul8 interface (that way i can turn them on/off via MIDI, OSC, or audio trigger…

    . you could send an email to support@garagecube.com and ask them to take a look at it.

    -james
    (a nomad. )
  • Invisible Ray
    member
    Posts: 33
    Joined: Mon May 16, 2011 11:50 pm

    Re: Loop function Broken in M8 2.9?

    by Invisible Ray » Fri Nov 20, 2015 11:49 pm

    Can you show me an example of activate/inactivate code? I use midi controllers sometimes, and I could incorporate it into my modules.
  • anomad
    master
    Posts: 411
    Joined: Sun Oct 21, 2007 10:07 pm
    Location: north cakalacky, usa
    Contact:

    Re: Loop function Broken in M8 2.9?

    by anomad » Sat Nov 21, 2015 6:44 pm

    . very basic stuff…

    . in Init() i'll have a variable named active =0

    . then depending on whether it's a switch (on or off) or momentary (on when held down, off when let go) i create the button accordingly and have the value of 'active' mirror the button GUI element

    . so, if it's something that uses periodicalEvent() i add

    global active

    if active :
    [rest of my code here]

    . otherwise i just check if active == 1 before running any code in message or direct event. so, the module is still running but effectively not processing any input until the variable active is true


    -james
    (a nomad .)

Who is online

Users browsing this forum: No registered users and 1 guest