StringValue
*เนื้อหานี้แปลโดยใช้ AI (เวอร์ชัน Beta) และอาจมีข้อผิดพลาด หากต้องการดูหน้านี้เป็นภาษาอังกฤษ ให้คลิกที่นี่
มูลค่าสตริงเป็นวัตถุที่มีวัตถุประสงค์เพื่อจัดเก็บสตริง Luau เดียว ความยาวของสตริงไม่สามารถเกิน 200,000 ตัวอักษร (จะทำให้เกิดข้อผิดพลาด "สตริงยาวเกินไป")เช่นเดียวกับวัตถุ "-Value" ทั้งหมด ค่าเดียวนี้จะถูกจัดเก็บในคุณสมบัติมูลค่าอีเวนต์ที่เปลี่ยนแปลงสำหรับสิ่งนี้ (และวัตถุอื่นๆ เช่นเดียวกับมัน) จะยิงด้วยค่าใหม่ที่ถูกเก็บไว้ในวัตถุแทนที่จะเป็นสตริงที่แทนที่คุณสมบัติที่เปลี่ยนแปลง
หากสตริงมีความยาวเกินไปที่จะแสดงในช่องมูลค่าภายในหน้าต่างคุณสมบัติ จะแสดงส่วนหนึ่งของเนื้อหาสตริงตามด้วยเลขยาว (...)
ตัวอย่างโค้ด
This sample demonstrates the subtleties of the Changed event on normal objects and "-Value" objects.
-- 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"
คุณสมบัติ
วิธีการ
อีเวนต์
Changed
ยิงเมื่อใดก็ตามที่ StringValue.Value ของ 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!".
local value = Instance.new("StringValue")
value.Parent = workspace
value.Changed:Connect(function(NewValue)
print(NewValue)
end)
value.Value = "Hello world!"