#Whats the point of using colon syntax in modules

1 messages · Page 1 of 1 (latest)

summer sigil
#

Basically module:doSomething()

I get that it has self but what's the point if you could just do module.blablabla

People say its more organised but how

If i use self the module don't know what it is and I need to define it at the bottom which some devs do and it's just feels like adding more stuff

If I'm not wrong it's sole purpose is for classes or metatables

wraith ravine
#

: just passes the table (self) as the first argument thats why u see it in oop structures since u dont have to constantly pass in the table as an argument. So yea its more organised since u have more space for arguments. Theres probs more advanced cases where u would pass the table as the first argument in a non oop module

static rover
#

its a getter

viral echo
#

let me give you an example

#

would you prefer

#
combat.Attack(character, damage, vfx, animation)
#

or

#
combat.new(character, base_dmg, vfx, animation)


events:connect(function()
if cd then return end
cd = true blablabla

combat:Attack()
end)
#

put it simply, you can pass in variables when you construct a new class(.new) then you can just use :() and you dont have to pass in arguments everytime

#

and it looks wayyy better and more organized

#

its more modular too

summer sigil
#

so its only use is in metatables?

#

like what if i dont want to construct a class

#

and its more of like basic utility modules

#

do i still need to use it?

viral echo
#

no

#

if its just basic utility then use normal .

#

only use : if you're gonna use OOP to organize a system

#

if its just for utility no need

summer sigil
#

Hm. Interesting

jagged ermine
#

You can also add typings with custom types and metatables

#

You'll get autocomplete when you use :

viral echo
#

thats what i recommend you to do

#

its really good

#

i basically add types to everything

#

jsut so i get the autocomplete

jagged ermine
viral echo
#

: Part

#

🙏

jagged ermine
#

No I mean for your modules?

viral echo
#

yeah something like that

#

the _Connection i'll set it to : {RBXScriptConnection}

#

since its gonna be multiple

#

I'll set Players to PlayerCount

#

its more understandable

summer sigil
#

What benefits can u get from doing ur code in vs

jagged ermine
#

I can also install packages that I can use for my scripts, they're basically like modules

#

and version control is so much better because of git

#

I can save my project to github