NumberValue

非推奨を表示

*このコンテンツは、ベータ版のAI(人工知能)を使用して翻訳されており、エラーが含まれている可能性があります。このページを英語で表示するには、 こちら をクリックしてください。

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"

プロパティ

Value

並列読み取り

ダブル値を保持するために使用されます。

方法

イベント

Changed

このイベントは、NumberValue.Value プロパティが変更されるたびに発動します。

このイベントは、他の変更されたイベントと同様、NumberValue が変更された時間を追跡し、変更される可能性のある異なる値を追跡することができます。

たとえば、これは、アイテムID などのゲーム状態と値を追跡するために NumberValues に依存するゲームでも有用かもしれません。

同等の変更イベントは、ObjectValueStringValue など、必要に最適なオブジェクトタイプによって異なります。

パラメータ

value: number

変更後の値。


コードサンプル

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