CoreObjectReference
A reference to a CoreObject which may or may not exist. This type is returned by CoreObject:GetCustomProperty()
for CoreObjectReference properties, and may be used to find the actual object if it exists.
In the case of networked objects it's possible to get a CoreObjectReference pointing to a CoreObject that hasn't been received on the client yet.
Properties
Property Name | Return Type | Description | Tags |
---|---|---|---|
id | string | The MUID of the referred object. | Read-Only |
isAssigned | boolean | Returns true if this reference has been assigned a valid ID. This does not necessarily mean the object currently exists. | Read-Only |
Functions
Function Name | Return Type | Description | Tags |
---|---|---|---|
GetObject() | CoreObject | Returns the CoreObject with a matching ID, if it exists. Will otherwise return nil. | None |
WaitForObject([number]) | CoreObject | Returns the CoreObject with a matching ID, if it exists. If it does not, yields the current task until the object is spawned. Optional timeout parameter will cause the task to resume with a return value of false and an error message if the object has not been spawned within that many seconds. | None |
Examples
Example using:
GetObject
WaitForObject
id
isAssigned
Sometimes you need to pass around a reference to a core object, instead of the actual object itself. This is most common when accessing custom properties - any core objects you have attached as custom properties are stored as CoreObjectReferences
.
A CoreObjectReference
is basically just a placeholder that you can use to access the original object. Except unlike the original object, the CoreObjectReference
is small and light, and can be passed around via Networked Custom Properties and Events.
This sample assumes that the script has a custom property of type CoreObjectReference
, which refers to the default floor in the scene.
-- The autogenerated code to access the custom property looks like this:
local propDefaultFloor = script:GetCustomProperty("DefaultFloor"):WaitForObject()
-- Since you usually don't care about the reference itself, and just want to
-- access the object, it normally appends WaitForObject(), to return the object
-- after waiting for it to load.
local floorObjectReference = script:GetCustomProperty("DefaultFloor")
-- If we didn't care about the object (possibly) not being loaded yet, we could
-- also just get the object directly:
local propDefaultFloor_noWaiting = floorObjectReference:GetObject()
-- We can also check things on the reference directly, such as if it has been
-- assigned to an object, and the MUID of the object it references:
if floorObjectReference.isAssigned then
print("The MUD is: " .. floorObjectReference.id)
end
See also: CoreObject.GetCustomProperty | CoreLua.print