Constructors: Difference between revisions

From Legacy Roblox Wiki
Jump to navigationJump to search
>JulienDethurens
No edit summary
m Text replacement - "</SyntaxHighlight>" to "</syntaxhighlight>"
 
(4 intermediate revisions by 2 users not shown)
Line 2: Line 2:
Constructors are functions which create an instance of data or a value of a specific type.
Constructors are functions which create an instance of data or a value of a specific type.
While some functions may return a specific data type, for instance, a Vector3, they are not considered a Constructor because they needed to call a constructor to make the value.
While some functions may return a specific data type, for instance, a Vector3, they are not considered a Constructor because they needed to call a constructor to make the value.
<code lua>function a(x, y)
<syntaxhighlight lang="lua">function a(x, y)
return Vector3.new(x.x, y.y, 0) -- A constructor is called here.
return Vector3.new(x.x, y.y, 0) -- A constructor is called here.
end</code>
end</syntaxhighlight>


==Examples==
==Examples==
<code lua>Vector3.new(x, y, z)
<syntaxhighlight lang="lua">Vector3.new(x, y, z)
Instance.new(n)
Instance.new(n)
CFrame.Angles(a, b, c)
CFrame.Angles(a, b, c)
</code>
</syntaxhighlight>


==See Also==
==See Also==
* [[Data Types]]
* [[Data Types]]

Latest revision as of 06:20, 27 April 2023

Introduction

Constructors are functions which create an instance of data or a value of a specific type. While some functions may return a specific data type, for instance, a Vector3, they are not considered a Constructor because they needed to call a constructor to make the value.

function a(x, y)
	return Vector3.new(x.x, y.y, 0) -- A constructor is called here.
end

Examples

Vector3.new(x, y, z)
Instance.new(n)
CFrame.Angles(a, b, c)

See Also