Passing a value from setup() to draw()

edited November 2013 in Programming Questions

Is there any way to pass a value from setup() to draw() without using global variables? I'm not an expert by any means, I probably wouldn't even pass for an intermediate level programmer, but I've always read that excessive use of global variables was poor programming practice.

Thanks...

Answers

  • Answer ✓

    well, setup() and draw() are actually methods in the same class - the preprocessor wraps them in a class definition as part of the compile* - so 'global' variables aren't really global, but class members.

    (* export one of your programs and then look in the created directory. there'll be a .java file created from your .pde where you can see the bits that have been added)

  • edited November 2013

    Cool- I did what you said and I see how it works, so I guess it's a matter of perspective.

    So, looking at the exported source and trying to understand it, what is making the draw() method loop indefinitely?

  • edited November 2013

    When a sketch starts, method PApplet.main() is invoked from within main().
    When all is set, it invokes our custom setup().
    Then keeps calling draw() and other triggered event custom functions indefinitely!
    That is called callback functions. >:)

Sign In or Register to comment.