Page 1 of 1

Loop function Broken in M8 2.9?

Posted: Wed Sep 23, 2015 10:09 pm
by Invisible Ray
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

Re: Loop function Broken in M8 2.9?

Posted: Thu Sep 24, 2015 4:04 pm
by Invisible Ray
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.

Re: Loop function Broken in M8 2.9?

Posted: Thu Sep 24, 2015 7:14 pm
by anomad
. 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. )

Re: Loop function Broken in M8 2.9?

Posted: Mon Oct 05, 2015 9:23 pm
by Invisible Ray
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.

Re: Loop function Broken in M8 2.9?

Posted: Mon Oct 05, 2015 10:34 pm
by anomad
. 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. )

Re: Loop function Broken in M8 2.9?

Posted: Tue Oct 27, 2015 2:56 pm
by Invisible Ray
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.

Re: Loop function Broken in M8 2.9?

Posted: Fri Nov 20, 2015 9:32 am
by Cbnxxd
hahaha this thread is too good.coquegsm

Re: Loop function Broken in M8 2.9?

Posted: Fri Nov 20, 2015 6:59 pm
by Invisible Ray
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?

Re: Loop function Broken in M8 2.9?

Posted: Fri Nov 20, 2015 9:45 pm
by anomad
. 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. )

Re: Loop function Broken in M8 2.9?

Posted: Fri Nov 20, 2015 11:49 pm
by Invisible Ray
Can you show me an example of activate/inactivate code? I use midi controllers sometimes, and I could incorporate it into my modules.

Re: Loop function Broken in M8 2.9?

Posted: Sat Nov 21, 2015 6:44 pm
by anomad
. 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 .)