#guys I have a question on how does oop work like

1 messages · Page 1 of 1 (latest)

somber pendant
#

npc Spawner has the default values and I want to do like if the function.new only gives health that the infos of the metatable get used and only the health changes, but how would I do that?

slim cloak
#

Maybe like this

local self = {}
... set values
setmetatable(self, npcSpawner)
return self

old nightBOT
#

studio** You are now Level 2! **studio

slim cloak
#

But i think it's cleaner to just do like
self.Health = health or DEFAULT_HEALTH
instead of this metatable magic

next ridge
#

Want me to code you an example?

amber leaf
next ridge
amber leaf
#

sorry

next ridge
#

Yg lol, no need to apologize

somber pendant
next ridge
somber pendant
somber pendant
next ridge
#

@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

somber pendant
#

I understand

#

can you also do me a favor?

next ridge
#

And to use those types you can do this as an example:

local function _TestFunction(Example: Example)
    print(Example.VeryCool)
end
next ridge
somber pendant
#

can you organize this

next ridge
#

No

somber pendant
#

bruh

next ridge
#

It's your code, your responsibility

somber pendant
#

any tips?

#

to organize?

next ridge
#

i'm not obligated nor should i be doing anything for you, it's your code and you should do it yourself

next ridge
somber pendant
next ridge
#

There's just too many parameters

#

Too many empty if blocks

#

i am genuinely concerned

somber pendant
next ridge
#

First of all, why are you making so many of the same variables? the Path variable

somber pendant
somber pendant
somber pendant
next ridge
#

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"

next ridge
#

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
next ridge
#

If CalculatePath returns something, and you don't use it, then don't wrap it in a variable

somber pendant
#

ok

next ridge
#

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"

somber pendant
next ridge
#

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

somber pendant
#

ok

next ridge
#

Very bad practise

somber pendant
#

also do you have any project idea I could do to add into my portfolio

next ridge
#

No

#

Figure it on your own

somber pendant
#

bruh

#

ok thanks tho