Engine-klasse
TextBox
*Deze inhoud is vertaald met behulp van AI (bèta) en kan fouten bevatten. Klik hier om deze pagina in het Engels te bekijken.
Samenvatting
Eigenschappen
Methoden
CaptureFocus():() |
ReleaseFocus(submitted: boolean):() |
Evenementen
FocusLost(enterPressed: boolean,inputThatCausedFocusLoss: InputObject):RBXScriptSignal |
Codevoorbeelden
TextBox Geheime Woord
-- Plaats deze code in een LocalScript binnen een TextBox
local textBox = script.Parent
local secretWord = "roblox"
local colorNormal = Color3.new(1, 1, 1) -- wit
local colorWrong = Color3.new(1, 0, 0) -- rood
local colorCorrect = Color3.new(0, 1, 0) -- groen
-- Initialiseer de staat van de textBox
textBox.ClearTextOnFocus = true
textBox.Text = ""
textBox.Font = Enum.Font.Code
textBox.PlaceholderText = "Wat is het geheime woord?"
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 = "TOEGANG TOEGESTAAN"
textBox.BackgroundColor3 = colorCorrect
else
textBox.Text = "TOEGANG GEWEIGERD"
textBox.BackgroundColor3 = colorWrong
end
else
-- De speler stopte met bewerken zonder op Enter te drukken
textBox.Text = ""
textBox.BackgroundColor3 = colorNormal
end
end
textBox.FocusLost:Connect(onFocusLost)
textBox.Focused:Connect(onFocused)API-referentie
Eigenschappen
CursorPosition
Codevoorbeelden
TextBox Selecties
local textBox = script.Parent
local function showSelection()
if textBox.CursorPosition == -1 or textBox.SelectionStart == -1 then
print("Geen selectie")
else
local selectedText = string.sub(
textBox.Text,
math.min(textBox.CursorPosition, textBox.SelectionStart),
math.max(textBox.CursorPosition, textBox.SelectionStart)
)
print('De selectie is:"', selectedText, '"')
end
end
textBox:GetPropertyChangedSignal("CursorPosition"):Connect(showSelection)
textBox:GetPropertyChangedSignal("SelectionStart"):Connect(showSelection)FontSize
SelectionStart
Codevoorbeelden
TextBox Selecties
local textBox = script.Parent
local function showSelection()
if textBox.CursorPosition == -1 or textBox.SelectionStart == -1 then
print("Geen selectie")
else
local selectedText = string.sub(
textBox.Text,
math.min(textBox.CursorPosition, textBox.SelectionStart),
math.max(textBox.CursorPosition, textBox.SelectionStart)
)
print('De selectie is:"', selectedText, '"')
end
end
textBox:GetPropertyChangedSignal("CursorPosition"):Connect(showSelection)
textBox:GetPropertyChangedSignal("SelectionStart"):Connect(showSelection)TextColor
TextColor3
Codevoorbeelden
Klinker Detector
local textBox = script.Parent
local function hasVowels(str)
return str:lower():find("[aeiou]")
end
local function onTextChanged()
local text = textBox.Text
-- Controleer op klinkers
if hasVowels(text) then
textBox.TextColor3 = Color3.new(0, 0, 0) -- Zwart
else
textBox.TextColor3 = Color3.new(1, 0, 0) -- Rood
end
end
textBox:GetPropertyChangedSignal("Text"):Connect(onTextChanged)TextWrap
Methoden
CaptureFocus
TextBox:CaptureFocus():()
Teruggaves
()
Codevoorbeelden
Vang Tekstvak Focus
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
Parameters
| Standaardwaarde: false |
Teruggaves
()
Codevoorbeelden
Focus van TextBox Vrijgeven
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)Evenementen
Focused
Codevoorbeelden
TextBox Focus
local textBox = script.Parent
textBox.Focused:Connect(function()
print("Gefocust!")
end)
textBox.FocusLost:Connect(function()
print("Focus verloren!")
end)FocusLost
Parameters
Codevoorbeelden
TextBox Focus
local textBox = script.Parent
textBox.Focused:Connect(function()
print("Gefocust!")
end)
textBox.FocusLost:Connect(function()
print("Focus verloren!")
end)FocusVerlies
local textBox = script.Parent
local function onFocusLost(enterPressed, inputThatCausedFocusLost)
if enterPressed then
print("Speler drukte op Enter")
else
print("Speler drukte op", 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("Focus is verloren omdat de enter-toets is ingedrukt!")
else
print("Focus is verloren zonder dat de enter-toets is ingedrukt")
end
end
textBox.FocusLost:Connect(focusLost)