I just got up to the part of the video where we create a “Weapon Damage” script. I think it’s getting a bit ridiculous with how many scripts we are creating and was wondering what the reason for this was.
I am only a student but I would generally just have one “Weapon” script, instead of having one script for every aspect/function/component of the weapon.
It’s good practice. Each component should have a single purpose. It allows for easy maintenance and extensibility.
Nothing stops you from putting all your code in a single Weapon
script, but with time you will discover that it is actually better to have components that does one thing, and one thing only
I have literally found the opposite to be true over time. I’m sick of looking for a script that I might have created or might not have, now I just put everything in one script. Like one “Movement”, it handles moving forward and moving back, etc.
I hate weeks down the line finding oh this character doesn’t have a “Move to the side” script on him. This is simplifying it. But I don’t see how it makes for easier maintenance and extensibility to have everything broken down all over the place like this.
This isn’t even going into having to manage all the namespaces in a project.
Yeah, that’s a little overkill. Movement.cs
is one thing. MoveLeft.cs
, MoveRight.cs
is insane and I have never seen anyone do that.
The instructors are trying to teach the best way to do something. If you don’t want to do it that way, you don’t have to. In programming, there are many ways to do the same thing. You do you, man
Well yeah. Idk why you are stating the obvious. I’m just trying to understand why you would do it this way. Or why this is “the best way”. Telling me something is just “the best way” or “It allows for easy maintenance and extensibility” without explaining how ain’t really answering my question/helping me out.
Of course I will do me, but you should put more thought into answers before responding to threads maybe.
While you wait for more thoughtful answers, why don’t you go and read about SOLID design principles, and also look at Celeste’s Player class and then tell me that class is better and more understandable
Running away screaming… No script should ever be that long. S is for Single Responsibility, not Single Script. At first, reading their readme, I thought they were joking, but this script actually looks like it will do everything they need in one 1000+ line script. :::shudder:::
You’re quite right, that is a bit of a cop out that is used quite often.
The Single Responsibility principle is much more than “easy maintenance and extensibility”.
- Easier to find bugs in the code base, assuming you are proficient with either a Debugger or with utilizing Debug.Logs.
- Makes classes portable. Let’s take the Health class, for example. Once you have a good health class in one project, if it’s sole responsibility is to track player’s health when getting hit or healed, then it’s easy to take that Health class out of project A and move it right into project B.
- Forces you to break problems down into smaller pieces. Generally speaking, the more your script is doing, the harder it is to spot bugs in the system.
- Makes code easier to follow for somebody joining your project. So I took a good long look at that Celeste’s Player Class… I’ve been writing code since before Ronald Reagan said “Mr. Gorbachev, Tear Down This Wall”. I consider myself really good at reading and understanding code, and if I were asked to try to make changes to that script I would just back away slowly and head for the door. In a team environment, you might have 5, 10, or 20 people working on the code.
I’m sure I’ve missed something here. These are my reasons for breaking code into units and following the S)ingle Responsibility Principle in S.O.L.I.D.
I understand single responsibility. You have a Health script for example. But you don’t seem to have a script for taking damage, then another for healing, say when you drink a health potion. You have a health script for managing the health.
Here we are breaking down the damage dealing and “turning weapon on/off” into two separate scripts. To me it seems to go beyond the principles mentioned before, of which I’m quite familiar. If this is just to demonstrate to very new students I can accept that.
From the projects I have worked on so far. This can go the other way as well. Breaking it down too far, making it harder for others in the team to follow what’s going on. Looking for scripts the next bit of code connects to and see where it’s been referenced already so you can connect to it.
But thank you for the thoughtful answer, I appreciate it.
- I wouldn’t read it because I’m already familiar with it.
- To me it is, yeah. Of course I would break it down a bit, maybe. But certainly I would not be breaking it down into hundreds of 10 line scripts. To me this is better, my IDE has a Ctrl + F function, and I’m generally pretty familiar with the projects I work on. And this player class doesn’t break any principle mentioned either. It’s sole responsibility is to control the player character (although Idk what kind of game Celeste is).
Since we are now setting each other homework; come back here when you’ve worked on an AoE-like RTS project where you were lead programmer and tell me you like everything broken down into 10 line scripts.
My answer was possibly a bit of a cop-out. I was writing an example but it’s hard to judge someone’s level of skill based on a single question, so I removed it again. My bad.
I admit I haven’t done this course, yet (I have it, but haven’t gotten around to it yet), and wasn’t aware of exactly how much ‘breaking up’ was happening so I generalized.
I was just trying to answer a question, not debate whether a game should be in a single script because then it’s sole responsibility is to run the game, so I will apologize and exit stage left
I think it’s a valid debate to have. But I didn’t know that’s what I was asking for when I posted this. To clarify I am a student of Game Production & Design. A year ago I had not touched Unity or Unreal. But I have a background in coding for over a decade.
So it maybe just I’m used to things that new people coming into game development aren’t in terms of coding. I think these courses are good, for example I had not considered to make the characters state it’s own class, previous I had only used an enum and had a switch case in Update for each state they may be in. But on the other hand I cringe at some of the habits/precedent being passed down to students in these courses. Such as how much is being copy’n’pasted between the player and enemy state classes.
I’m sorry if my responses sounded angry, I was writing them between doing lectures in this course while I’m shouting at the screen in frustration about how badly things are being done.
The Health script would need to be able to adjust the health based on taking damage or receiving healing. It’s responsibility is to accept that damage/healing and adjust the health accordingly.
It doesn’t contain all the functionality of a Heal spell, for example, it doesn’t respond to a hypothetical Drink Potion command. You would need a separate class for this that responds to an input event Heal, and tells Health to Heal a certain amount.
It doesn’t contain all the functionality of damaging. It has no idea (nor does it care) where the damage came from. That could be a WeaponDamage component (which itself has been told that damage should occur by the collider/rigidbody issuing an OnTriggerEnter) or it could be a component on a campfire damaging any character that stands in the fire. I’ve even got damage set up in mine if the time spent in FallingState exceeds a certain threshhold. All of these damage sources simply call Health.TakeDamage(amount).
One important thing to remember is that these courses are written for complete beginners who have absolutely no coding experience whatsoever. The courses address a very broad audience of inexperienced people, to include children.
There will be things that do not make any sense to an experienced/professional programmer.
The code needs to be simple enough for a beginner (or a child) to understand.
The instructors will often go back and refactor things, which also helps the student understand the importance of refactoring and how to do it.
I don’t think you quite understand.
A health script should/would respond to a Drink Health potion command. You would have that method in there. You wouldn’t have a seperate script that connects Health Potions to Health with the Heal method seperatly in this connecting script. There is no need for that.
Another example would be a firearm script. You don’t have a script for the trigger, you just have a Trigger Pulled method in the firearm script. It’s logical to have it there. Braking things down trying to make than arbitrarily more complex actually causes more problems.
Your last paragraph makes no sense, I have no idea what point your trying to make there. You just go from trying explain why it needs to be this way (which you are 100% wrong about) to talking about some random thing you did in your own project.
At the end of the day it’s what fits the project you’re working. And I have yet to work on a project that needs to have every method be put into it’s own seperate script.
This makes a lot of sense. It’s an important skills to have: being able to see what needs to be refactored, how the code could be more efficient.
It makes sense to me now for them to be commiting these big no no’s.
Hey @final_synapse, why are you still doing this course then? If everything is wrong, the explanations given were “100% wrong “, then there’s no incentive for you to continue any of the courses here. I started my journey as a game dev a year ago with these courses and found the teachings, style, and general way of doing things one of the best.
Especially the RPG course, where this way of thinking works out quite well (single responsibility script). It seems you are quite the advanced developer that finds all these things trivial and wrong without providing any real solution or thinking why “your way” is the “right way.”
If you favor single monolithic scripts, I recommend you take any of these courses
https://sharpaccent.com/
I tried a couple of them, and they all follow the “ player-manager/ health manager/input manager / etc. “ way of doing things
Good luck with your game dev journey!
Good God! This thing reads like a filibuster!
This is a great way to ensure that NOBODY else wants to work on your game!
To be fair, a person probably ‘could’ put all of their code into one script…just as a person ‘could’ point a telescope at the sun…
…but that doesn’t mean it’s a good idea.
There are just some things that are probably better not to do.
(Jeez, that Celeste code is crazy!)
There is no need for this discussion to become toxic.