StringValue

Visualizza obsoleti

*Questo contenuto è tradotto usando AI (Beta) e potrebbe contenere errori. Per visualizzare questa pagina in inglese, clicca qui.

Un StringValue è un oggetto il cui scopo è quello di memorizzare un singolo Luau string.La lunghezza della stringa non può essere superiore a 200.000 caratteri (questo causerà un errore "Stringa troppo lunga").Come tutti gli oggetti "-Value", questo singolo valore viene memorizzato nella ProprietàValore.L'evento modificato per questo (e altri oggetti come esso) si attiverà con il nuovo valore memorizzato nell'oggetto, invece di una stringa che rappresenta la proprietà che viene modificata.

Se la stringa è troppo lunga da essere visualizzata nel campo Valore nella finestra Proprietà, mostrerà parzialmente i contenuti della stringa seguiti da un'ellisse (...).

Campioni di codice

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"

Proprietà

Value

Lettura Parallela

La stringa memorizzata .

Metodi

Eventi

Changed

Sparato ogni volta che viene modificato il StringValue.Value del StringValue .Funzionerà con il nuovo valore memorizzato nell'argomento oggetto, invece di una stringa che rappresenta la proprietà che viene modificata.

Questo evento, come altri eventi modificati, può essere utilizzato per tracciare quando un StringValue cambia e per tracciare i diversi valori che può cambiare.

Ad esempio, questo può essere utile in giochi che si affidano a StringValues per tracciare valori come NPC o nomi di oggetti.

Eventi equivalenti modificati esistono per oggetti simili, come NumberValue e BoolValue, a seconda del tipo di oggetto che meglio soddisfa il bisogno.

Parametri

value: string

Il nuovo valore dopo il cambiamento.


Campioni di codice

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