I want to make something like a command line, but it got much more advanced than expected.
I’ve got to where it does print out text after pressing Enter, but I can’t manage what would be printing. Now I have a function looking like this:
local function UpdateCurrentText()
currentText = textBox.Text
end
local function NextLine(enterPressed, _inputObject)
if enterPressed then
local guess = currentText
if guess == currentText .. "F:\Users\VenciB>" then
textBox.Text = currentText .. "\nF:\Users\VenciB>"
elseif guess == currentText .. "SecretDIR" then
textBox.Text = currentText .. "\nOpen notepad.exe?\n[Y] Yes, [N] No\nF:\Users\VenciB>"
else
textBox.Text = currentText .. "\nFile or directory not found.\nF:\Users\VenciB>"
textBox.Text = currentText
end
else
textBox.Text = currentText
end
end
textBox.FocusLost:Connect(NextLine)
textBox:GetPropertyChangedSignal("Text"):Connect(UpdateCurrentText)
I believe that the problem is with getting the last sentence that was written, it always prints out “File or directory not found.” if you didn’t know by now.
So can anyone explain how I can get the last thing the user has written and forgets the text before it? For instance, after some printing the text in the textbox would look like this:
F:\Users\VenciB>fa
File or directory not found.
F:UsersVenciB>gd
File or directory not found.
F:UsersVenciB>j
File or directory not found.
F:UsersVenciB>
File or directory not found.
F:UsersVenciB>
File or directory not found.
F:UsersVenciB>
File or directory not found.
F:UsersVenciB>
File or directory not found.
F:UsersVenciB> SecretDIR ← something I want to type, still prints the text above
And my intention in the script was it to print something else. So got any ideas?
local function UpdateCurrentText()
local txt = textBox.text:split('\n')
currentText = txt[#txt]
end
local function NextLine(enterPressed, _inputObject)
if enterPressed then
local guess = currentText
if guess == currentText .. "F:\Users\VenciB>" then
textBox.Text = currentText .. "\nF:\Users\VenciB>"
elseif guess == currentText .. "SecretDIR" then
textBox.Text = currentText .. "\nOpen notepad.exe?\n[Y] Yes, [N] No\nF:\Users\VenciB>"
else
textBox.Text = currentText .. "\nFile or directory not found.\nF:\Users\VenciB>"
textBox.Text = currentText
end
else
textBox.Text = currentText
end
end
textBox.FocusLost:Connect(NextLine)
textBox:GetPropertyChangedSignal("Text"):Connect(UpdateCurrentText)
That worked, but it has a clear flaw.
After typing in SecretDIR it works as it should, but continues the same response over and over, as the text still contains the word. Is there any other function that might be useful?
Yeah you’re going to need to use some string manipulation. A combination of string.len and string.sub. This should work:
local function NextLine(enterPressed, _inputObject)
if enterPressed then
local guess = currentText
local v=string.len(guess)
if string.sub(guess,1,v) == "F:\Users\VenciB>" then
textBox.Text = currentText .. "\nF:\Users\VenciB>"
elseif string.sub(guess,1,v) == "F:\Users\VenciB>SecretDIR" then
textBox.Text = currentText .. "\nOpen notepad.exe?\n[Y] Yes, [N] No\nF:\Users\VenciB>"
else
textBox.Text = currentText .. "\nFile or directory not found.\nF:\Users\VenciB>"
textBox.Text = currentText
end
else
textBox.Text = currentText
end
end