Context
I can’t seem to find many resources on the topic of applying pseudoclasses beyond, well, making a simple pseudoclass that doesn’t quite extract the full benefits of streamlining behaviour for something.
Sample class, written to reflect what I know.
local Class = {}
local ClassMeta = {}
ClassMeta.__index = ClassMeta
function ClassMeta:ABTest()
print(self)
end
function Class.new()
local classObject = {}
setmetatable(classObject, ClassMeta)
return classObject
end
return Class
I find that this structure of OOP itself is pretty ugly and have generally conditioned myself not to use any kind of OOP in my code, since my pseudoclasses are easily achievable by writing a non-OOP ModuleScript or some kind of other piece of code.
Recently, I’ve wanted to get into trying out OOP once again for my code and becoming overambitious to step out of my comfort zone with scripting. I figure that I want to try to make use of a concept and learn about it more than leave it idly in the back of my mind.
Problem
Given the above context, I would like to begin by attempting to create a tool pseudoclass, specifically a weapon pseudoclass, that essentially handles all the scripting for weapons. The only problem is… I haven’t the slightest of where to begin or how to make things flow together.
I’ll post what I have for now.
Tool
Since my goal is to streamline behaviour for all weapons, I include nothing but a configuration ModuleScript in the tool. This holds data about the tool. Anything else that’s local to the tool can be added as well, but the main point is scripts - I only have a data module.
Scripts
And this is where I get stuck, somewhat.
So from what I’m assuming based on what I’m familiar with, this whole gun system would be running off of only two scripts. The server handler script would reside in ServerScriptService and be responsible for the gun’s traffic and server-side needs, while the LocalScript would be in StarterPlayerScripts.
I have absolutely no clue where the class would go. Assuming that the server is only handling class traffic and doesn’t have any need to access the class, my best guess would be ReplicatedStorage or StarterPlayerScripts under a class folder.
Class
Once I’ve set up my scripts, it’s time to write the actual class. I assume it’d be not far off from the code example in my Context section above. I’ve been reading through a couple of threads involving weapon classes but they’re above my level; they involve inheritance, superclasses and subclasses.
Naturally, I have no clue how to set up a weapon class. I’ve been reading a couple resources such as the all-popular All About Object-Oriented Programming, but I feel that isn’t sufficient to help me understand. I’m scouting resources but I’d like any links you guys might have for OOP.
Getting the Class Connected
Once somehow my class is connected, that’s where I need to begin working on the LocalScript specifically (again, this is assuming the server has no business accessing the gun class, unless this is something that needs to be done). This is also where I draw the blank.
How exactly am I supposed to get my gun class to scale perfectly with as many weapons as I want? I don’t know how to connect the ModuleScript to work with weapons or handle post-respawn setup. This is a single LocalScript in PlayerScripts that needs to work with all weapons and function as expected when a respawn, backpack rearrangement (adding/removing tools) or otherwise edit of tools happens.
I appreciate any help and pointers that can be given. Please do not spoon feed code (e.g. posting a chunk of code), this isn’t going to help me learn. I’m looking for wisdom as well as knowledge, not knowledge alone.