Friday, March 2, 2012


Naming variables
Scratch is very lenient when it comes to naming variables. You may use letters, numbers, special characters and spaces to make names as long as you like.  Other programming languages do not allow spaces in names, starting variable names with numbers and using special characters and JAVA is case sensitive.  I advise learners to choose variable names similar to the ones we would use in the programming language they will use from grade 11: meaningful names, without spaces or special characters and using capitals to separate words e.g. total, subTotal, areaOfSquare etc

A variable’s scope determines where the variable’s value can be modified:
  • For all sprites: can be modified by the script of any sprite.  These variables are available when you set or change variables in the scripts of any sprite

  • For this sprite only: can only be modified by scripts belonging to this sprite.  Encourage learners to use local variables whenever possible. It is good programming practice  and decreases the possibility that you might accidentally modify the variable’s value using scripts belonging to other sprites.  The private variables appear below the grey line of available variables

  • Their assigned values can be accessed by scripts belonging to other sprites, however, using sensing blocks.  This is an excellent illustration of private variables and methods of a class.  Accessors can be used to display and use private variables.  The mutator methods, set and change, are private methods and not available to other sprites.  Even if the learners cannot fully appreciate or understand this concept yet, it is good to mention it now and refer to it again later.

No comments:

Post a Comment