Structural Class: Difference between revisions

From Legacy Roblox Wiki
Jump to navigationJump to search
>Samacado
A lot of pages linked to it so I wrote an article on it. I don't like calling is a structural class.
 
>Emess
No edit summary
 
(4 intermediate revisions by 3 users not shown)
Line 3: Line 3:
No structural classes can be created in the game, sub-classes of them can be.
No structural classes can be created in the game, sub-classes of them can be.


For example; the objects [[Part]], [[Truss]], and [[WedgePart]] all inherit their properties from the structural class [[BasePart]]; and all of the GUI objects inherit their properties and methods from [[GuiBase]].
For example; the objects [[Part]], [[TrussPart]], and [[WedgePart]] all inherit their properties from the structural class [[BasePart]]; and all of the GUI objects inherit their properties and methods from [[GuiBase]].


They are used to create objects, that while similar, play different roles. A [[Truss]] and a [[Part]] are quite similar in concept, and would require all of the same methods and properties, but are slightly divergent.
They are used to create objects, that while similar, play different roles. A [[TrussPart]] and a [[Part]] are quite similar in concept, and would require all of the same methods and properties, but are slightly divergent.


<pre>
<pre>
Line 12: Line 12:
     Part
     Part
     WedgePart
     WedgePart
     Truss
     TrussPart
   GuiBase
   GuiBase
     ScreenGui
     ScreenGui
Line 18: Line 18:
     TextButton
     TextButton
</pre>
</pre>


{{Example|
{{Example|
Using the [[isA]] method, we can demonstrate the concept of superclasses.
Using the [[IsA]] method, we can demonstrate the concept of superclasses.
<pre>
<pre>
wedge = Instance.new("WedgePart")
wedge = Instance.new("WedgePart"))
print(wedge:isA("BasePart")
print(wedge:IsA("BasePart"))
print(wedge:isA("WedgePart")
print(wedge:IsA("WedgePart"))
print(wedge:isA("Part")
print(wedge:IsA("Part"))
print(wedge:isA("Instance")
print(wedge:IsA("Instance"))
</pre>
</pre>
would result in
would result in

Latest revision as of 03:40, 18 February 2011

A structural class (in the context of ROBLOX), or superclass is an object which is not actually used or possible to instantiate in-game, but is used as the basis from which certain other objects to inherit certain properties, events, and methods. All global properties are inherited from Instance, and then further structural classes exist.

No structural classes can be created in the game, sub-classes of them can be.

For example; the objects Part, TrussPart, and WedgePart all inherit their properties from the structural class BasePart; and all of the GUI objects inherit their properties and methods from GuiBase.

They are used to create objects, that while similar, play different roles. A TrussPart and a Part are quite similar in concept, and would require all of the same methods and properties, but are slightly divergent.

Instance
  BasePart
    Part
    WedgePart
    TrussPart
  GuiBase
    ScreenGui
    ImageLabel
    TextButton
Example

Using the IsA method, we can demonstrate the concept of superclasses.

wedge = Instance.new("WedgePart"))
print(wedge:IsA("BasePart"))
print(wedge:IsA("WedgePart"))
print(wedge:IsA("Part"))
print(wedge:IsA("Instance"))

would result in

true
true
false
true

WedgePart and Part share the same structural class BasePart, and are thus both considered to be BaseParts. WedgePart is also obviously a WedgePart, but it is important to note that WedgePart is not also a Part, just because of their shared ancestry. Additionally, all objects in ROBLOX inherit their properties from Instance, and thus all objects are considered to be an Instance.