Engine-Klasse
TextBox
*Dieser Inhalt wurde mit KI (Beta) übersetzt und kann Fehler enthalten. Um diese Seite auf Englisch zu sehen, klicke hier.
Zusammenfassung
Eigenschaften
Methoden
CaptureFocus():() |
ReleaseFocus(submitted: boolean):() |
Events
FocusLost(enterPressed: boolean,inputThatCausedFocusLoss: InputObject):RBXScriptSignal |
Code-Beispiele
TextBox geheimes Wort
-- Platziere diesen Code in einem LocalScript innerhalb einer TextBox
local textBox = script.Parent
local secretWord = "roblox"
local colorNormal = Color3.new(1, 1, 1) -- weiß
local colorWrong = Color3.new(1, 0, 0) -- rot
local colorCorrect = Color3.new(0, 1, 0) -- grün
-- Initialisiere den Zustand der textBox
textBox.ClearTextOnFocus = true
textBox.Text = ""
textBox.Font = Enum.Font.Code
textBox.PlaceholderText = "Was ist das geheime Wort?"
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 = "ZUGANG ERTEILT"
textBox.BackgroundColor3 = colorCorrect
else
textBox.Text = "ZUGANG VERWEIGERT"
textBox.BackgroundColor3 = colorWrong
end
else
-- Der Spieler hat das Bearbeiten ohne Drücken von Enter beendet
textBox.Text = ""
textBox.BackgroundColor3 = colorNormal
end
end
textBox.FocusLost:Connect(onFocusLost)
textBox.Focused:Connect(onFocused)API-Referenz
Eigenschaften
CursorPosition
Code-Beispiele
TextBox-Auswahlen
local textBox = script.Parent
local function showSelection()
if textBox.CursorPosition == -1 or textBox.SelectionStart == -1 then
print("Keine Auswahl")
else
local selectedText = string.sub(
textBox.Text,
math.min(textBox.CursorPosition, textBox.SelectionStart),
math.max(textBox.CursorPosition, textBox.SelectionStart)
)
print('Die Auswahl ist:"', selectedText, '"')
end
end
textBox:GetPropertyChangedSignal("CursorPosition"):Connect(showSelection)
textBox:GetPropertyChangedSignal("SelectionStart"):Connect(showSelection)FontSize
SelectionStart
Code-Beispiele
TextBox-Auswahlen
local textBox = script.Parent
local function showSelection()
if textBox.CursorPosition == -1 or textBox.SelectionStart == -1 then
print("Keine Auswahl")
else
local selectedText = string.sub(
textBox.Text,
math.min(textBox.CursorPosition, textBox.SelectionStart),
math.max(textBox.CursorPosition, textBox.SelectionStart)
)
print('Die Auswahl ist:"', selectedText, '"')
end
end
textBox:GetPropertyChangedSignal("CursorPosition"):Connect(showSelection)
textBox:GetPropertyChangedSignal("SelectionStart"):Connect(showSelection)TextColor
TextColor3
Code-Beispiele
Vokal Detector
local textBox = script.Parent
local function hasVowels(str)
return str:lower():find("[aeiou]")
end
local function onTextChanged()
local text = textBox.Text
-- Überprüfen Sie auf Vokale
if hasVowels(text) then
textBox.TextColor3 = Color3.new(0, 0, 0) -- Schwarz
else
textBox.TextColor3 = Color3.new(1, 0, 0) -- Rot
end
end
textBox:GetPropertyChangedSignal("Text"):Connect(onTextChanged)TextWrap
Methoden
CaptureFocus
TextBox:CaptureFocus():()
Rückgaben
()
Code-Beispiele
Fokus auf TextBox erfassen
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
Parameter
| Standardwert: false |
Rückgaben
()
Code-Beispiele
Fokus des Textfeldes freigeben
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)Events
Focused
Code-Beispiele
TextBox Fokus
local textBox = script.Parent
textBox.Focused:Connect(function()
print("Fokussiert!")
end)
textBox.FocusLost:Connect(function()
print("Fokus verloren!")
end)FocusLost
Parameter
Code-Beispiele
TextBox Fokus
local textBox = script.Parent
textBox.Focused:Connect(function()
print("Fokussiert!")
end)
textBox.FocusLost:Connect(function()
print("Fokus verloren!")
end)FokusVerloren
local textBox = script.Parent
local function onFocusLost(enterPressed, inputThatCausedFocusLost)
if enterPressed then
print("Spieler hat Eingabetaste gedrückt")
else
print("Spieler hat gedrückt", 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("Der Fokus ging verloren, weil Enter gedrückt wurde!")
else
print("Der Fokus ging verloren, ohne dass Enter gedrückt wurde")
end
end
textBox.FocusLost:Connect(focusLost)