Classe motore
TextBox
*Questo contenuto è tradotto usando AI (Beta) e potrebbe contenere errori. Per visualizzare questa pagina in inglese, clicca qui.
Sommario
Proprietà
Metodi
CaptureFocus():() |
ReleaseFocus(submitted: boolean):() |
Eventi
FocusLost(enterPressed: boolean,inputThatCausedFocusLoss: InputObject):RBXScriptSignal |
Campioni di codice
Parola Segreta TextBox
-- Inserisci questo codice in un LocalScript all'interno di un TextBox
local textBox = script.Parent
local secretWord = "roblox"
local colorNormal = Color3.new(1, 1, 1) -- bianco
local colorWrong = Color3.new(1, 0, 0) -- rosso
local colorCorrect = Color3.new(0, 1, 0) -- verde
-- Inizializza lo stato del textBox
textBox.ClearTextOnFocus = true
textBox.Text = ""
textBox.Font = Enum.Font.Code
textBox.PlaceholderText = "Qual è la parola segreta?"
textBox.BackgroundColor3 = colorNormal
local function onFocused()
textBox.BackgroundColor3 = colorNormal
end
local function onFocusLost(enterPressed, _inputObject)
if enterPressed then
local guess = textBox.Text
if guess == secretWord then
textBox.Text = "ACCESSO CONSENTITO"
textBox.BackgroundColor3 = colorCorrect
else
textBox.Text = "ACCESSO NEGATO"
textBox.BackgroundColor3 = colorWrong
end
else
-- Il giocatore ha smesso di modificare senza premere Invio
textBox.Text = ""
textBox.BackgroundColor3 = colorNormal
end
end
textBox.FocusLost:Connect(onFocusLost)
textBox.Focused:Connect(onFocused)Riferimento API
Proprietà
CursorPosition
Campioni di codice
Selezioni della Casella di Testo
local textBox = script.Parent
local function showSelection()
if textBox.CursorPosition == -1 or textBox.SelectionStart == -1 then
print("Nessuna selezione")
else
local selectedText = string.sub(
textBox.Text,
math.min(textBox.CursorPosition, textBox.SelectionStart),
math.max(textBox.CursorPosition, textBox.SelectionStart)
)
print('La selezione è: "', selectedText, '"')
end
end
textBox:GetPropertyChangedSignal("CursorPosition"):Connect(showSelection)
textBox:GetPropertyChangedSignal("SelectionStart"):Connect(showSelection)FontSize
SelectionStart
Campioni di codice
Selezioni della Casella di Testo
local textBox = script.Parent
local function showSelection()
if textBox.CursorPosition == -1 or textBox.SelectionStart == -1 then
print("Nessuna selezione")
else
local selectedText = string.sub(
textBox.Text,
math.min(textBox.CursorPosition, textBox.SelectionStart),
math.max(textBox.CursorPosition, textBox.SelectionStart)
)
print('La selezione è: "', selectedText, '"')
end
end
textBox:GetPropertyChangedSignal("CursorPosition"):Connect(showSelection)
textBox:GetPropertyChangedSignal("SelectionStart"):Connect(showSelection)TextColor
TextColor3
Campioni di codice
Rilevatore di Vocali
local textBox = script.Parent
local function hasVowels(str)
return str:lower():find("[aeiou]")
end
local function onTextChanged()
local text = textBox.Text
-- Controlla le vocali
if hasVowels(text) then
textBox.TextColor3 = Color3.new(0, 0, 0) -- Nero
else
textBox.TextColor3 = Color3.new(1, 0, 0) -- Rosso
end
end
textBox:GetPropertyChangedSignal("Text"):Connect(onTextChanged)TextWrap
Metodi
CaptureFocus
TextBox:CaptureFocus():()
Restituzioni
()
Campioni di codice
Cattura Focus del TextBox
local UserInputService = game:GetService("UserInputService")
local textBox = script.Parent
local input = UserInputService.InputBegan:Connect(function(input, processed)
if input.KeyCode == Enum.KeyCode.Q then
textBox:CaptureFocus()
end
end)ReleaseFocus
Parametri
| Valore predefinito: false |
Restituzioni
()
Campioni di codice
Rilascia Focus TextBox
local UserInputService = game:GetService("UserInputService")
local textBox = script.Parent
local input = UserInputService.InputBegan:Connect(function(input, processed)
if input.KeyCode == Enum.KeyCode.Escape and textBox.IsFocused then
textBox:ReleaseFocus()
end
end)Eventi
Focused
Campioni di codice
Focus della Casella di Testo
local textBox = script.Parent
textBox.Focused:Connect(function()
print("Focalizzato!")
end)
textBox.FocusLost:Connect(function()
print("Focus perso!")
end)FocusLost
Parametri
Campioni di codice
Focus della Casella di Testo
local textBox = script.Parent
textBox.Focused:Connect(function()
print("Focalizzato!")
end)
textBox.FocusLost:Connect(function()
print("Focus perso!")
end)PerditaFocalizzazione
local textBox = script.Parent
local function onFocusLost(enterPressed, inputThatCausedFocusLost)
if enterPressed then
print("Il giocatore ha premuto Invio")
else
print("Il giocatore ha premuto", inputThatCausedFocusLost.KeyCode)
end
end
textBox.FocusLost:Connect(onFocusLost)TextBox.FocusLost1
local gui = script.Parent
local textBox = gui.TextBox
local function focusLost(enterPressed)
if enterPressed then
print("Il focus è stato perso perché è stato premuto invio!")
else
print("Il focus è stato perso senza che fosse premuto invio")
end
end
textBox.FocusLost:Connect(focusLost)