StringValue

顯示已棄用項目

*此內容是使用 AI(Beta 測試版)翻譯,可能含有錯誤。若要以英文檢視此頁面,請按一下這裡

一個 StringValue 是一個用於儲存單個 Luau 字串 的目標的對象。字串長度不能超過 200,000 個字元 (這會導致「字串過長」錯誤)。像所有 "-Value" 對象一樣,這個單值存儲在價值屬性中。對於這個 (以及其他像它一樣的對象) 所做的更改事件將使用新值存儲在對物件中,而不是使用代表被更改的屬性的字串。

如果字串過長以至於無法在屬性窗戶中的值欄中顯示,它將顯示一部分字串內容,以及一個 ellipsis(...)。

範例程式碼

This sample demonstrates the subtleties of the Changed event on normal objects and "-Value" objects.

Changed Event

-- 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"

屬性

Value

平行讀取

儲存的 字串

方法

活動

Changed

每當 StringValue.ValueStringValue 被更改時,都會發射。它將使用新值存儲在參數對物件中,而不是代表正在變更的屬性的字串。

這個事件,像其他已變更的事件一樣,可以用來跟蹤當 StringValue 變更時以及可能變更的不同值。

例個體、實例,這可能對依賴 StringValues 來跟蹤值,例如 NPC 或物品名稱的遊戲有用。

相同類型的變更事件存在於類似物件,例如 NumberValueBoolValue,取決於哪種物件類型最適合需求。

參數

value: string

變更後的新值。


範例程式碼

The below example, assuming all referenced objects existed, would print the StringValue's new value each time it changed. In the example below it would print "Hello world!".

How to Use StringValue.Changed

local value = Instance.new("StringValue")
value.Parent = workspace
value.Changed:Connect(function(NewValue)
print(NewValue)
end)
value.Value = "Hello world!"