Friday, August 3, 2012

Unexpected results

As you know you can start multiple events that will run "simultaneously" in Scratch. What will happen if you have three sprites and all three sprites assign different values to the same variable when the green flag is clicked?
The elephant assigns 1 to x, the Dino assigns 2 to x and the Lion assigns 3 to x when the gree flag is clicked.

My program displays 2 ?!

1 comment:

  1. Firstly, I would like to thank you for your blog. I am an avid reader and I am in Grade 10. In response to your confusion, this is my theory: Scratch stores its sprites in a type of list/queue structure, and thus the sprite that you touched least recently, will have its code executed "last", thus it will have the final say in the value of x. Try this: click-on/move the lion, then the elephant, then the dino, and the number should be 3.