Difference between revisions of "Super"
Jump to navigation
Jump to search
(Added example code) |
m (Fix yet another typo) |
||
(One intermediate revision by the same user not shown) | |||
Line 5: | Line 5: | ||
<ms> | <ms> | ||
− | //PLANT base | + | //PLANT base class |
PLANT = new Sprite | PLANT = new Sprite | ||
PLANT.image = Image.create(25, 25, color.lime) | PLANT.image = Image.create(25, 25, color.lime) | ||
Line 32: | Line 32: | ||
//loop for tree.grow | //loop for tree.grow | ||
− | while not tree.scale | + | while not tree.scale == tree.maxGrowth |
tree.grow | tree.grow | ||
wait .5 | wait .5 |
Latest revision as of 22:11, 12 March 2022
super
is a keyword used to access base class methods from within a subclass method. It is part of MiniScript's support for object-oriented programming.
Example code:
//PLANT base class
PLANT = new Sprite
PLANT.image = Image.create(25, 25, color.lime)
PLANT.maxGrowth = 20
PLANT.scale = 0
PLANT.grow = function
self.scale = self.scale + .1
if self.scale > self.maxGrowth then
self.scale = self.maxGrowth
return
end if
end function
//tree subclass
tree = new PLANT
tree.x = 480
tree.y = 320
tree.grow = function //trees function that would override grow within the PLANT base class
super.grow //reaches out to the PLANT base class and calls it
print "I grew!" //end of the function prints after super.grow is called.
end function
//pushes tree to default sprite display
display(4).sprites.push tree
//loop for tree.grow
while not tree.scale == tree.maxGrowth
tree.grow
wait .5
end while
This article is a stub. You can help the MiniScript Wiki by expanding it.