#guys I have a question on how does oop work like
1 messages · Page 1 of 1 (latest)
Maybe like this
local self = {}
... set values
setmetatable(self, npcSpawner)
return self
** You are now Level 2! **
But i think it's cleaner to just do like
self.Health = health or DEFAULT_HEALTH
instead of this metatable magic
This is a simple and basic way of doing OOP, a more advanced way is to introduce type annotation to your code, also instead of a bunch of parameters you can do a table and put values inside of that, way cleaner
Want me to code you an example?
btw you should merge all those parameters into one table. Lua shouldnt have a lot of horizontal length. You can exclude crtain stats by adding another table of stats you dont want and just referencing that.
For your issue you can just use or liek teh guy above said.
I already said all that, but thanks for your input
sorry
Yg lol, no need to apologize
wdym with type annotation?
Do you know what it is? Or have you never heard of it before?
is it this?: ...
so can you tell?
@somber pendant It's basically when you give a undefined variable a type
an example is:
local Players = game:GetService("Player")
local Player: Player = Players.LocalPlayer
You see that ": Player"
That basically tell the linter "Hey, this variable is containing a player"
You can also make custom types, which is used a lot
Example:
type Test = {
Example: string
}
You can also assign roblox types to those types
Example:
type PlayerType = Player
And if you want a type to be accessable from other scripts then you add export before the type
Example:
export type Example = {
VeryCool: boolean
}
There's more, example generic types and stuff, but you can just search on youtube and do your own research
And to use those types you can do this as an example:
local function _TestFunction(Example: Example)
print(Example.VeryCool)
end
wsp?
No
bruh
It's your code, your responsibility
i'm not obligated nor should i be doing anything for you, it's your code and you should do it yourself
Give me a moment to check it out
k
so what else can I do?
First of all, why are you making so many of the same variables? the Path variable
I mean I also was after I thought I had to script an npc system
the path is another function variable
a function to move the npcs there
Second of all, all the empty if blocks are dumb, this is what the linter thinks when it comes to your empty if blocks:
"If self.Waypoint then i should do nothing, if there's no waypoint then i should execute this code"
You should instead make it "if self.Waypoint isn't true then i should execute this code"
ok
So instead of ```lua
if self.Waypoint then
else
print("Moving to waypoint")
local num = math.random(#self.Waypoints:GetChildren())
local waypoints = self.Waypoints:GetChildren()
local waypoint = waypoints[num]
self.Waypoint = waypoint
end
do:
```lua
if not self.Waypoint then
print("Moving to waypoint")
local num = math.random(#self.Waypoints:GetChildren())
local waypoints = self.Waypoints:GetChildren()
local waypoint = waypoints[num]
self.Waypoint = waypoint
end
You're not even using the path variable
If CalculatePath returns something, and you don't use it, then don't wrap it in a variable
ok
And your naming convention is very inconsistent
Most of the time you name it short like example: "dis" for Distance, other times you do PascalCase example: "TriggeringOrSelfAttacking", other times you do camelCase / lowercase example: "attacking"
ik Pascal for important or self. thing and lowercase if variable and short because of laziness
And that's a problem
i'd recommend sticking to PascalCase
And if you're experiencing issues with understanding variables, then it's your problem if you can't name them properly
ok
Very bad practise
also do you have any project idea I could do to add into my portfolio