I was wondering if there is the possibility of inheritance in Defold. So I took a look at the Side Scroller Tutorial, cause I remembered that there is a normal star and a bonus star. Both stars have their own script, but 95% of their code is exactly the same. I personally don’t like repetitive code, so inheritance would be really nice in this case.
My question is now: Can scripts or GameObjects inherit from each other?
No, what you need to do is divide it into behaviours, where different scripts are responsible for different things. In that particular case though - if I remember the purpose of bonus stars correctly - you could have one script but with speed and points as properties that you set from the editor.
Yes, that is exactly what I mean!
You could even call the first script something like “can_move.script”, have the speed as a property and share that code between stars and the space ship. The only difference would be the spaceship would have it’s speed set from another script that takes keyboard input and the stars would have the speed set at creation time.
You can either compose behavior with separate scripts components and prime them with data through script properties (see http://www.defold.com/ref/go#go.property) or you can compose several interacting game objects in collections.