Apologies if this is a silly question but I am stuck on figuring out the best approach to tackle my issue.
Basically i have created an intractable system, works really well does everything I need. It works really well on doors, just select the door and open nothing to crazy. But then I needed to create this for a french door. So basically two doors side by side. I named each door so left being left and right being right. The door script was on the left door but when it came to the right I didn’t want to re-do everything all over again. So I attached the same script to the other door, connected the signals and everything actually works.
So my question, is this really the right way to go about this. I noticed someone ask something similar and someone gave an answer https://forum.godotengine.org/t/best-practises-for-reusable-customizable-component-design/53627/3 but i really am not sure if that was an answer? Maybe I am missing something. I did some research around composition and inheritance but I don’t see the inherent benefit in my situation. I get if I wanted some sort of uniqueness then a class would make sense, but on a door that simply opens away from the player and closes to original I thought maybe this was just simpler. Curious what others think
I think its fine, if you truly didn’t change any code then I think you succeeded in code usability.
I don’t want to ramble, but I would say try your best to make reusable code, but don’t worry about getting it completely right. you can always refactor, if it becomes too hard to work with. And sometimes its not always necessary to make reusable code every time.
Failing and getting stuck with code is usually a great place to learn how to solve a particular issue. Design patterns are a great source to study such issues on code/data organization.
There’s no right way to do things, always analyze according to your requirements, scope, etc., be mindful of AHA (search about “the wrong abstraction”), it’s a really important concept in games because things change too much in early stages.
With Godot in particular you have some basic options like doing generic scripts that can work on different scenes, use composition with nodes or with scripts.
Another option is to make generic scenes that work different with specialized scripts.
Inheritance of scripts, scenes and resources, etc. give you a lot of options more to reuse code, scenes, data structures and values.
The most important thing is to be consistent with whatever approach you take and always remember that there will be design changes in the near future.