一个 NumberValue 是一个用于存储单个 Luau 数字 的对象,定义为 双精度浮点数字 或更常见地称为 双倍 。这里使用 IEEE 754 表示(1 个符号位、11 个指数位和 52 个分数位)来存储 64 位(8 字节)的数字。最大可存储的数值为 2^53,或 9,007,199,254,740,992,最小值为 -9,007,199,254,740,992。它可以存储高达 15 位精度。
像所有 "-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"
概要
活动
每当 NumberValue.Value 被更改时发射。
属性
方法
活动
Changed
这个事件会在 NumberValue.Value 属性发生改变时触发。
这个事件,像其他更改的事件一样,可以用来跟踪当 NumberValue 发生变更时以及可能更改的不同值。
例如,这甚至可能在依赖 NumberValues 来跟踪游戏状态和价值的游戏中有用,例如物品 ID。
相同类型的更改事件存在于类似对象,例如 ObjectValue 和 StringValue,根据需求最适合的对象类型进行选择
参数
更改后的值。
代码示例
This example prints the NumberValue's new value each time it changes. Here it prints 20.
NumberValue Changed
local numberValue = script.Parent.NumberValue
local function printValue(value)
print(value)
end
numberValue.Changed:Connect(printValue)
numberValue.Value = 20