요약
속성
메서드
CaptureFocus():() |
ReleaseFocus(submitted: boolean):() |
이벤트
FocusLost(enterPressed: boolean,inputThatCausedFocusLoss: InputObject):RBXScriptSignal |
상속된 멤버
코드 샘플
텍스트박스 비밀 단어
-- 이 코드를 텍스트박스 안의 LocalScript에 배치하세요
local textBox = script.Parent
local secretWord = "roblox"
local colorNormal = Color3.new(1, 1, 1) -- 흰색
local colorWrong = Color3.new(1, 0, 0) -- 빨간색
local colorCorrect = Color3.new(0, 1, 0) -- 초록색
-- textBox의 상태 초기화
textBox.ClearTextOnFocus = true
textBox.Text = ""
textBox.Font = Enum.Font.Code
textBox.PlaceholderText = "비밀 단어는 무엇인가요?"
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 = "접근 허가됨"
textBox.BackgroundColor3 = colorCorrect
else
textBox.Text = "접근 거부됨"
textBox.BackgroundColor3 = colorWrong
end
else
-- 플레이어가 Enter를 누르지 않고 편집을 중지했습니다.
textBox.Text = ""
textBox.BackgroundColor3 = colorNormal
end
end
textBox.FocusLost:Connect(onFocusLost)
textBox.Focused:Connect(onFocused)API 참조
속성
CursorPosition
코드 샘플
텍스트 박스 선택
local textBox = script.Parent
local function showSelection()
if textBox.CursorPosition == -1 or textBox.SelectionStart == -1 then
print("선택 없음")
else
local selectedText = string.sub(
textBox.Text,
math.min(textBox.CursorPosition, textBox.SelectionStart),
math.max(textBox.CursorPosition, textBox.SelectionStart)
)
print('선택된 내용은:"', selectedText, '"입니다')
end
end
textBox:GetPropertyChangedSignal("CursorPosition"):Connect(showSelection)
textBox:GetPropertyChangedSignal("SelectionStart"):Connect(showSelection)FontSize
SelectionStart
코드 샘플
텍스트 박스 선택
local textBox = script.Parent
local function showSelection()
if textBox.CursorPosition == -1 or textBox.SelectionStart == -1 then
print("선택 없음")
else
local selectedText = string.sub(
textBox.Text,
math.min(textBox.CursorPosition, textBox.SelectionStart),
math.max(textBox.CursorPosition, textBox.SelectionStart)
)
print('선택된 내용은:"', selectedText, '"입니다')
end
end
textBox:GetPropertyChangedSignal("CursorPosition"):Connect(showSelection)
textBox:GetPropertyChangedSignal("SelectionStart"):Connect(showSelection)TextColor
TextColor3
코드 샘플
모음 탐지기
local textBox = script.Parent
local function hasVowels(str)
return str:lower():find("[aeiou]")
end
local function onTextChanged()
local text = textBox.Text
-- 모음 체크
if hasVowels(text) then
textBox.TextColor3 = Color3.new(0, 0, 0) -- 검정색
else
textBox.TextColor3 = Color3.new(1, 0, 0) -- 빨간색
end
end
textBox:GetPropertyChangedSignal("Text"):Connect(onTextChanged)TextWrap
메서드
CaptureFocus
TextBox:CaptureFocus():()
반환
()
코드 샘플
텍스트박스 포커스 잡기
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
매개 변수
| 기본값: false |
반환
()
코드 샘플
텍스트 박스 포커스 해제
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)이벤트
Focused
코드 샘플
텍스트박스 포커스
local textBox = script.Parent
textBox.Focused:Connect(function()
print("포커스가 맞춰졌습니다!")
end)
textBox.FocusLost:Connect(function()
print("포커스가 잃었습니다!")
end)FocusLost
매개 변수
코드 샘플
텍스트박스 포커스
local textBox = script.Parent
textBox.Focused:Connect(function()
print("포커스가 맞춰졌습니다!")
end)
textBox.FocusLost:Connect(function()
print("포커스가 잃었습니다!")
end)포커스 손실
local textBox = script.Parent
local function onFocusLost(enterPressed, inputThatCausedFocusLost)
if enterPressed then
print("플레이어가 Enter를 눌렀습니다")
else
print("플레이어가", inputThatCausedFocusLost.KeyCode를 눌렀습니다)
end
end
textBox.FocusLost:Connect(onFocusLost)텍스트박스.포커스잃음1
local gui = script.Parent
local textBox = gui.TextBox
local function focusLost(enterPressed)
if enterPressed then
print("포커스가 잃어버렸습니다. Enter가 눌렸기 때문입니다!")
else
print("Enter가 눌리지 않고 포커스를 잃었습니다")
end
end
textBox.FocusLost:Connect(focusLost)