StringValue

显示已弃用

*此内容使用人工智能(Beta)翻译,可能包含错误。若要查看英文页面,请点按 此处

一个 StringValue 是一个用于存储单个 Luau 字符串 的目标的对象。字符串长度不能超过 200,000 个字符(这将导致“字符串太长”错误)。像所有 "-Value" 对象一样,这个单值被存储在价值属性中。为此更改的事件(以及其他类似的对象)将使用新值在对象中存储,而不是使用代表被更改的属性的字符串发射。

如果字符串过长以至于无法显示在属性窗口的值字段中,它将部分显示字符串内容,并跟随一个空格(...)。

代码示例

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