I was simply looking in some code but i saw two values separated by a colon like this:
Character:Model
What is this called/mean?
Edit: I shortened the title so people wouldnt have to click on the topic to see the entire question.
I was simply looking in some code but i saw two values separated by a colon like this:
Character:Model
What is this called/mean?
Edit: I shortened the title so people wouldnt have to click on the topic to see the entire question.
This is called “type checking” it denotes the type of a variable and what you should set it to. e.g
local Character: Model = Player.Character;
Character is a model.
so whats the difference without it? would it be the same?
It would be the exact same, you aren’t obligated to utilize type checking!
In fact if you do not fully understand it I would advise you to stick with the basics as it can actually confuse things.
This syntax is a type declaration. While Lua is a dynamically typed language and variables have no inherit type, you can use this as a reminder to yourself and others what type this variable is supposed to be. For example, you may see something like this:
local function squareNum(num: number): number
return num ^ 2
end
This simply means that that the function squareNum
is expecting a number argument, and then will return some other number. However, this does not force the variable num
to be a number, and any non-number variable can be passed into it.
Another benefit of declaring variable types like this is that the Roblox code editor will pick up on the type and provide suggestions for functions that can be done on an object of the given type.
Ohhhh so its just to help yourself remember what type that variable is
Thank you guys for your help
It’s to denote what parameters a function accepts and / or the type of a variable / constant.
But basically yes.
Also if you’ve found your solution please select it so no one answers an resolved post!
Alright, thanks again!
3 0char
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.