Function not called...very confused

Hi Everyone,

I teach both CS Discoveries and AP CSP (caveat: I’m a new CS teacher entirely. This is my first year teaching Discoveries, and 2nd year teaching CSP. My background is math and statistics). As I was prepping Lesson 7, I saw that when the code is run in Bubble 3, there is an infinite loop that happens…however, the draw() function is never called with draw();.

I’m confused. Calling a function after defining it is a fundamental I learned in AP CSP training. Am I missing something?

1 Like

Ms. Salas,

Excellent catch, as I didn’t develop the platform, I cannot speak to things specifically but my two thoughts:

1.) This is still early in the students understanding and perhaps it’s viewed as a “see what it does” rather than getting caught up in calling it

OR

2.) I know the GameLab was developed with Processing (java based language in mind) which treats the Draw function as the main function that always runs when you run the program. You can still create specialized functions that would need to be called separately - but in Processing you’d need that draw function to create anything to post to the screen.

Hope that helps!
Brad

Yes, this is really weird and screws people up all of the time. Who calls the draw function is a question I got a lot when I piloted this unit. The call to the draw function is hidden and it gets called repeated, forever.
You can change how many times it is called per second by setting the frameRate on the world before the draw loop.

World.frameRate = 5 ;

Or I suppose you could change the frameRate in the draw loop to change how fast frame get drawn during the animation or game.

The other question I got a lot was, “How do you stop the draw function?” I think the answer is, you can not stop it. :stuck_out_tongue_winking_eye: