Environment
All Roblox games, including RetroStudio, have their own environment where your parts, models, scripts, etc. are stored. You are likely aware that your game's main content is stored in Workspace
.
It is often important to interact with the environment by adding new objects, modifying or deleting existing objects. This is done using indexing.
Indexing involves using a "path" to get to a certain object or property. Paths can begin from game
, workspace
, or a variable containing an object.
Let's say that we want to make a part in Workspace called "Block" red. Here's how you would do it:
workspace.Block.BrickColor
means that you want to set the BrickColor
property of workspace.Block
, and that you want to set it to BrickColor.new("Really red")
, which creates a BrickColor with a red color.
But what is BrickColor? It is a special type that represents a color. We will go over special types like it in a separate page.
As you might have guessed, we can not only modify existing objects, but also create new ones. This is done using the Instance.new()
function. Note that the "I" in Instance is capitalized.
Let's adapt our previous example to create a new part instead of using an existing one:
The first line will create a Part in workspace, and assign it to the variable block. The second line will rename the part to be called Block (therefore accessible as workspace.Block). The third line will set the part's BrickColor to Really red.
As you noticed, Instance.new()
takes two arguments: the type of the object you want to create, and where you want to put the new object.
Each object also has its own functions. These functions can do special operations with the object, such as deleting or cloning it. Let's take a look at how we can delete an object:
Therefore, if you have a part called "Block" in workspace, this code will delete (or "destroy") it. Note the usage of : instead of . before Destroy()
. This is because the : character signifies that the function has to be performed on an object.
In Lua, workspace.Block:Destroy()
is functionally identical to workspace.Block.Destroy(workspace.Block)
. The latter usage of the function is not supported in Powerlang due to compiler limitations.
You can use this Roblox Documentation webpage to determine what operations you can do with objects: https://create.roblox.com/docs/reference/engine/classes/Instance (Note that newer functions will not work, as RetroStudio is focused on delivering an old Roblox experience).
In the next page we will discuss special types and see more ways of using them.
Last updated