Page 1 of 1

Stupid code newbie question.

Posted: Sun Jan 16, 2011 5:15 am
by lotech
I'm attempting to merge a couple of modules to save on screen space. My understanding of coding modules is basic but so far I've managed to get everything working except I get an error on opening modul8, and by the looks of things it only needs a simple fix.

So I've inserted this into PeriodicalEvent(elapsed):

Code: Select all

# crossfader control
if run :
   
   if sec > 0 :
      pos = modul8.getValue ('ctrl_master_crossfader_slider',0)
      inc = (elapsed / sec) * dir
      pos += inc
      
      if pos > 1 : pos = 1; run = 0
      elif pos < 0 : pos = 0 ; run = 0
   
   elif dir == 1 : pos = 1 ; run = 0
   else : pos = 0 ; run = 0
   
   modul8.setValue ('ctrl_master_crossfader_slider',pos,0)


And then when I open Modul8 I get:
"NameError: name 'run' is not defined"

So some pointers on how do I best define a name for the above code.
Thanks.

Posted: Sun Jan 16, 2011 8:19 pm
by anomad
. if you've defined the variable 'run' in Init() add the line


global run


. at the beginning of PeriodicalEvent

-james
(a nomad. )

Posted: Sun Jan 16, 2011 10:33 pm
by lotech
Thanks, I tried that and still am a bit stuck/confused. I've uploaded it here if someone wants to have a look.

No Download (as we fixed it).

I imagine its a 10 second fix.

Posted: Mon Jan 17, 2011 12:54 am
by anomad
. i didn't see run defined in Init()

. i added it under last_time = 0.0

run = 0


. save, reload - two syntax errors
. reload again, no errors! :)

-james
(a nomad. )

Posted: Mon Jan 17, 2011 3:18 am
by lotech
Wicked thanks - I got another error about sec not being defined - so I did the same with sec = 0 in the init().

I'll stick the final module in the online library.
Thanks again.