Stupid code newbie question.
  • User avatar
    lotech
    ultim8 member
    Posts: 228
    Joined: Wed Feb 06, 2008 1:26 am
    Location: Auckland, NZ
    Contact:

    Stupid code newbie question.

    by lotech » Sun Jan 16, 2011 5:15 am

    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.
  • anomad
    master
    Posts: 412
    Joined: Sun Oct 21, 2007 10:07 pm
    Location: north cakalacky, usa
    Contact:

    by anomad » Sun Jan 16, 2011 8:19 pm

    . if you've defined the variable 'run' in Init() add the line


    global run


    . at the beginning of PeriodicalEvent

    -james
    (a nomad. )
  • User avatar
    lotech
    ultim8 member
    Posts: 228
    Joined: Wed Feb 06, 2008 1:26 am
    Location: Auckland, NZ
    Contact:

    by lotech » Sun Jan 16, 2011 10:33 pm

    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.
    Last edited by lotech on Mon Jan 17, 2011 4:21 am, edited 1 time in total.
  • anomad
    master
    Posts: 412
    Joined: Sun Oct 21, 2007 10:07 pm
    Location: north cakalacky, usa
    Contact:

    by anomad » Mon Jan 17, 2011 12:54 am

    . 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. )
  • User avatar
    lotech
    ultim8 member
    Posts: 228
    Joined: Wed Feb 06, 2008 1:26 am
    Location: Auckland, NZ
    Contact:

    by lotech » Mon Jan 17, 2011 3:18 am

    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.

Who is online

Users browsing this forum: No registered users and 20 guests