----------------
-- Class: Animal
----------------
Animal = class()
function Animal:init( word )
self.talk = word
end
function Animal:speak()
print( self.talk )
end
----------------
-- Class: Dog
----------------
Dog = class(Animal)
function Dog:init()
Animal.init( self, "Woof" )
end
----------------
-- Main
----------------
function setup()
d = Dog()
d:speak()
c = Animal("Meow")
c:speak()
end
This works no problem, but if you separate the classes across two files, it will not inherit the Animal class. How do I separate the class in two files and still be able to inherit?
1/ from your project A editor, tap the + sign on top right.
2/ in ‘dependencies’, check the other project B with you classes.
tadaaaaa! project A knows your classes in B
I figured it out, file execution order matters. The classes are excuted from left to right in the tab, I had my super class execute after the subclass inherited, so my subclass was inheriting when the superclass was still null.
@Simeon had to pick some order for compiling the tabs. The choices available were either alphabetical, time created, or how they’re ordered in the project.