StringValue

顯示已棄用項目

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

StringValue 是一個用於存儲單個 Lua 字串 的對象。字串的長度不能超過 200,000 個字元 (此將導致 "String too long" 錯誤)。 與所有 "-Value" 對象一樣,此單一值存儲在 "值" 屬性。 Changed 事件發生時 (和其他對象一樣)

如果字串過長,以至於在屬性窗口內的價值字段中顯示,它會在一個空格 (...) 後顯示部分字串內容。

範例程式碼

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 變更時。它會在新值被存儲在參數物件中,而不是在 string 代表屬性變更的字串。

這個事件,像其他變更的事件,可以用來追蹤字串值變更時間和追蹤它可能變更的不同值。

舉個體、實例來說,這可能有助於遊戲,以便追蹤值,例如 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!"