Ever had a sprite that displayed the wrong picture?
Many of the old KPL examples use global methods such as "LoadSprite". As programmers evolve to Phrogram, a typical piece of code for loading a Sprite may look like this:
Define mySprite As Sprite = LoadSprite("mypic.gif")
(My code turned out to contain these)
Beware! in effect you are registering the sprite in some internal table under a name you do not control. This means you will get the following behaviour:
Define flowerSprite As Sprite = LoadSprite("flower.gif")
Define gunSprite As Sprite = LoadSprite("gun.gif")
flowerSprite.stamp()
//THIS WILL DISPLAY A GUN! Two solutions exist:
(1) Bad solution - Use "LoadSprite" with a unique name. It works, but means that you must manage these names - an unnecessary drag in Phrogram's OO world
(2) Good Solution: Avoid global functions and more importantly - the global namespace. Use member methods:
Define flowerSprite As Sprite
flowerSprite.Load("flower.gif") // Now nothing will put a gun on my screen.
Happy Spriting.