개체는 Roblox 클래스 계층의 모든 클래스의 기본 클래스입니다.Roblox 엔진에서 정의하는 다른 모든 클래스는 Object의 모든 멤버를 상속합니다.직접 개체를 생성할 수는 없습니다.
요약
메서드
특정 개체의 속성이 변경될 때 발생하는 이벤트를 가져옵니다.Get an event that fires when a given property of the object changes.
개체의 클래스가 지정된 클래스와 일치하거나 상속하는 경우 true를 반환합니다.
이벤트
속성이 변경된 후 즉시 해고되지만, 몇 가지 제한 사항이 있습니다.
속성
ClassName
이 Object에 속하는 클래스를 나타내는 읽기 전용 문자열.
이 속성은 입력개체를 식별하는 데 사용되는 다양한 다른 함수와 함께 사용할 수 있습니다(예: Object:IsA() 또는 Instance:FindFirstChildOfClass()).
이 속성은 읽기 전용이므로 스크립트에서 변경할 수 없습니다.개체의 클래스를 변경하려는 개발자는 대신 새로운 Object를 만들어야 합니다.
Object:IsA() 와 달리 ClassName을 사용하여 개체가 특정 클래스에 속하는지 여부를 확인할 수 있습니다. 예를 들어:
for _, child in workspace:GetChildren() doif child.ClassName == "Part" thenprint("Found a Part")-- will find Parts in model, but NOT TrussParts, WedgeParts, etcendend
메서드
GetPropertyChangedSignal
이 메서드는 지정된 속성이 변경될 때만 발생하는 이벤트와 동일하게 동작하는 이벤트를 반환하지만, 지정된 속성이 변경될 때만 발생합니다.일반적으로 속성 이름을 확인하는 함수로 연결하는 대신 이 메서드를 사용하는 것이 좋습니다 Changed .동일한 속성 이름을 가진 동일한 개체에서 이 메서드에 대한 후속 호출은 동일한 이벤트를 반환합니다.
ValueBase 개체, 예를 들어 IntValue 및 StringValue , 자신의 속성 Changed 내용으로 발생하는 수정된 Value 이벤트를 사용합니다.따라서 이 메서드는 해당 개체의 다른 속성에서 변경 사항을 감지하는 방법을 제공합니다.
이 이벤트는 연결된 함수에 아무 인수도 전달하지 않으므로 변경된 속성의 값은 스크립트 내에서 직접 읽어야 합니다.
제한
이 메서드에서 반환된 이벤트는 발사하지 않고 물리 관련 변경, 예를 들어 , , , , 또는 중력에 의한 변화의 속성을 변경합니다.이러한 속성의 변경을 감지하려면 RunService.PreSimulation와 같은 물리 기반 이벤트를 사용하는 것을 고려하십시오.
또한 반환된 이벤트는 매우 자주 변경되는 속성의 모든 수정에서 발생하지 않을 수도 있고/또는 그러한 속성에 대해 전체발생하지 않을 수도 있습니다.게임 논리에 영향을 주는 속성 변경을 신중하게 테스트하는 것이 좋습니다.
매개 변수
연결할 속성.
반환
속성이 변경될 때마다 발생하는 신호입니다.
코드 샘플
This code sample demonstrates how to save a value before a changed event fires on it in order to get more information about a change.
local part = Instance.new("Part")
local currentColor = part.BrickColor
local function onBrickColorChanged()
local newColor = part.BrickColor
print("Color changed from", currentColor.Name, "to", newColor.Name)
currentColor = newColor
end
part:GetPropertyChangedSignal("BrickColor"):Connect(onBrickColorChanged)
part.BrickColor = BrickColor.new("Really red")
part.BrickColor = BrickColor.new("Really blue")
This code sample demonstrates the equivalence of the Changed event and event returned by GetPropertyChangedSignal.
local part = Instance.new("Part")
local function onBrickColorChanged()
print("My color is now " .. part.BrickColor.Name)
end
local function onChanged(property)
if property == "BrickColor" then
onBrickColorChanged()
end
end
part:GetPropertyChangedSignal("BrickColor"):Connect(onBrickColorChanged)
part.Changed:Connect(onChanged)
-- Trigger some changes (because we connected twice,
-- both of these will cause two calls to onBrickColorChanged)
part.BrickColor = BrickColor.new("Really red")
part.BrickColor = BrickColor.new("Institutional white")
IsA
IsA는 개체의 클래스가 와 동일하거나 지정된 클래스의 하위 클래스 인 경우 true를 반환합니다.이 함수는 다른 언어의 instanceof 연산자와 유사하며, 형식 내부 조사의 형태입니다.클래스 상속을 무시하려면 ClassName 속성을 직접 테스트하십시오.네이티브 Luau 데이터 유형(숫자, 문자열 등)을 확인하려면 함수 type 및 typeof을 사용하십시오.
가장 일반적으로 이 함수는 개체가 어떤 종류의 부품인지 테스트하기 위해 사용되며, 예를 들어 Part 또는 WedgePart , 이는 상속받은 BasePart (추상 클래스)에서 파생됩니다.예를 들어, 모든 문자의 팔을 동일한 색으로 변경하는 것이 목표라면, GetChildren 를 사용하여 자식을 반복하고 IsA를 사용하여 속성 BasePart 이 없는 비BrickColor 개체를 필터링할 수 있습니다.
local Players = game:GetService("Players")
local function paintFigure(character, color)
-- 캐릭터의 자식 개체를 반복하여 검사
for _, child in character:GetChildren() do
-- 셔츠, 바지 및 휴머노이드와 같은 부분이 아닌 개체를 필터링합니다
-- R15는 MeshPart를 사용하고 R6는 부품을 사용하므로 여기에서 둘 모두를 감지하기 위해 BasePart를 사용합니다.
if child:IsA("BasePart") then
child.BrickColor = color
end
end
end
paintFigure(Players.Player.Character, BrickColor.new("Bright blue"))
모든 클래스가 Object에서 상속하기 때문에, object:IsA("Object")를 호출하면 항상 true가 반환됩니다.
매개 변수
개체의 클래스에 대해 확인할 클래스입니다. 대/소문자를 구분합니다.
반환
개체의 클래스가 일치했는지 또는 지정된 클래스의 하위 클래스인지 설명합니다.
코드 샘플
Demonstrates determining the class of Workspace using Instance:IsA()
Workspace is of class 'Workspace', so the first statement is true. Workspace is not of class 'BasePart', so the second statement is false. Workspace inherits from Instance and therefore is of class 'Instance', so the third statement is true.
local Workspace = game:GetService("Workspace")
print(Workspace:IsA("Workspace")) -- true
print(Workspace:IsA("BasePart")) -- false
print(Workspace:IsA("Instance")) -- true
이벤트
Changed
이 이벤트는 개체 속성이 변경된 후 즉시 발생하며 대부분의 사용 사례에서 작동합니다(아래의 제한 사항 참조).변경된 속성의 새 값은 매개 변수로 전달되지 않으므로 를 사용하여 액세스해야 합니다.예를 들어:
object.Changed:Connect(function(property)
print("The new property's value is", object[property])
end)
특정 속성의 변경 사항만 듣는 데 관심이 있는 경우 GetPropertyChangedSignal() 메서드를 대신 사용하는 것이 좋습니다.
For ValueBase 개체, IntValue 및 StringValue와 같은 개체의 경우, 이 이벤트는 개체의 Value 속성이 변경될 때만 발생합니다.ValueBase 개체의 다른 변경 사항을 감지하려면 GetPropertyChangedSignal() 대신 사용하십시오.
제한
이 이벤트는 발사하지 않습니다 물리 관련 변경, 예를 들어 , , , 또는 중력으로 인해 발생하는 변화의 속성에 대해 발사하지 않습니다.이러한 속성의 변경을 감지하려면 RunService.PreSimulation와 같은 물리 기반 이벤트를 사용하는 것을 고려하십시오.
또한 이 이벤트는 매우 자주 변경되는 속성의 모든 수정에서 발생하지 않을 수 있고/또는 그러한 속성에 대해 전체발생하지 않을 수 있습니다.게임 논리에 영향을 주는 속성 변경을 신중하게 테스트하는 것이 좋습니다.
매개 변수
변경된 속성의 이름.
코드 샘플
This sample demonstrates the subtleties of the Changed event on normal objects and "-Value" objects.
-- Demonstrate the Changed event by creating a Part
local part = Instance.new("Part")
part.Changed:Connect(print)
-- This fires Changed with "Transparency"
part.Transparency = 0.5
-- Similarly, this fires Changed with "Number"
part.Name = "SomePart"
-- Since changing BrickColor will also change other
-- properties at the same time, this line fires Changed
-- with "BrickColor", "Color3" and "Color3uint16".
part.BrickColor = BrickColor.Red()
-- A NumberValue holds a double-precision floating-point number
local vNumber = Instance.new("NumberValue")
vNumber.Changed:Connect(print)
-- This fires Changed with 123.456 (not "Value")
vNumber.Value = 123.456
-- This does not fire Changed
vNumber.Name = "SomeNumber"
-- A StringValue stores one string
local vString = Instance.new("StringValue")
vString.Changed:Connect(print)
-- This fires Changed with "Hello" (not "Value")
vString.Value = "Hello"
This code sample demonstrates the Changed event firing within a parent object.
local object = script.Parent
local function onChanged(property)
-- Get the current value of the property
local value = object[property]
-- Print a message saying what changed
print(object:GetFullName() .. "." .. property .. " (" .. typeof(value) .. ") changed to " .. tostring(value))
end
object.Changed:Connect(onChanged)
-- Trigger a simple change in the object (add an underscore to the name)
object.Name = "_" .. object.Name