Special types

The basic data types in Powerlang are numbers, strings (text) and booleans (true/false). However, this isn't enough to represent every property an object might have. For instance, parts have their own colors and positions which cannot be described using these data types. That's why special types exist - they help represent properties not describable with numbers or text. An example of special types are: colors (BrickColor and Color3), positions (Vector3, Vector2, UDim2), etc. Let's go over each type in detail.

Colors

Both Roblox and RetroStudio have two data types to represent colors: BrickColor and Color3. The difference is that BrickColor is limited to a specific color palette, whereas Color3 can represent any color a computer screen can show. BrickColor predates Color3, therefore it is used in older objects like parts. On the other hand, newer objects like UI use Color3. Remember to consult with the Roblox API to know what color type to use. Here is a demonstration of both BrickColor and Color3:

workspace.Part.BrickColor = BrickColor.new("Really red")
game.StarterGui.ScreenGui.SomeFrame.BackgroundColor3 = Color3.new(1,1,1)

The code snippet above assigns the Really red color of the BrickColor palette to a part in Workspace and a white color (1,1,1) to a Frame in StarterGui. You can find available BrickColor options in the Roblox Documentation: https://create.roblox.com/docs/reference/engine/datatypes/BrickColor

Positions

There are three data types supported by RetroStudio that represent positions: Vector3, Vector2 and UDim2. Additionally, there is a matrix type that can represent both a position and a rotation, CFrame. However, CFrame can be confusing for beginners and is not fully supported by RetroStudio, so it will not be mentioned in this article.

Vector3 represents a three-dimensional point in the game world. Vector2 represents a two-dimensional point. UDim2 represents a two-dimensional point or size in UI.

Vector3 and Vector2 types are predominantly used in 3D world operations, whereas UDim2 is used exclusively for UI.

Here's an example of using Vector3 to set a part's size:

workspace.Part.Size = Vector3.new(5,5,5)

This code will set the size of a part in Workspace to be 5 studs along each axis.

Here's an example of using UDim2 to set a UI element's size:

game.StarterGui.ScreenGui.Frame.Size = UDim2.new(1, 0, 1, 0)

As you can see, 4 arguments are input into UDim2.new(). The first and third arguments represent the X and Y axis percentages, while the second and fourth arguments represent the X and Y axis offsets. For example, if you set the first argument to 1, then the Frame will occupy 1*100% of the user's X axis. If you set the second argument to 500, then the Frame will occupy 500 pixels of the user's X axis.


On the next page we'll discuss functions.

Last updated