StringValue 是一个用于存储单个 Lua 字符串 的对象。长度不能多于 200,000 个字符 (此将导致一个 "字符串过长" 错误)。 像其他 "String 对象" 一样,此单个值都存储在值属性中。 更改事件将在更改属性时触发,而不是在更改对象。
如果字符串过长,它将在 Properties 窗口中的值字段中显示一个空格(...)后的字符串内容。
代码示例
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"
概要
活动
发射,当 StringValue.Value 发生变更。
属性
方法
活动
Changed
发射时,当 StringValue.Value 的 StringValue 改变时。它将运行使用新值存储在参数对中,而不是使用 StringValue 来表示属性正在更改。
这个事件,像其他更改的事件,可以用来跟踪StringValue的更改时间和跟踪它可能更改的不同值。
例实例,这可能对于依赖 StringValues 追踪值,例如 NPC 或物品名的游戏有所帮助。
对于类似对象,例如 NumberValue 和 BoolValue,等级变更为适合需求的最佳对象类型。
参数
更改后的新值。
代码示例
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!"