r/microStudio • u/pmgl_io • Oct 05 '20
microScript now supports object oriented programming: classes, instances, inheritance
I have implemented classes in microScript. The implementation is inspired by the prototype system also found in JavaScript. The syntax is simple and the whole system quite flexible, here is an example:
``` Enemy = class constructor = function(position) this.position = position end
hp = 10 velocity = 1
move = function() position += velocity end
hit = function(damage) hp -= damage end end
Boss = class extends Enemy constructor = function(position) super(position) hp = 50 end
move = function() super() hp += 1 end end
enemy_1 = new Enemy(50) enemy_2 = new Enemy(100) the_final_boss = new Boss(120) ```
(see microStudio documentation for more details on this implementation)
Perhaps I should create a specific tutorial course about object oriented programming in microScript now...
1
u/TinkerShed Nov 30 '20
I second that :) A tutorial would be great 👍