Getting command player wants to enter from few characters input

  1. What do you want to achieve? Keep it simple and clear!
    So i wan’t do something like this:
    so like list of command what match string entered by player
  2. What is the issue? Include screenshots / videos if possible!
    qwe123
    I have no point how to detect TextBox each time player enters new character
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub? Nothing found

Current detect of textbox code

Console.MainFrame.ConsoleFrame.TextBox.FocusLost:Connect(function(ep)
		if ep then
			local text = console.MainFrame.ConsoleFrame.TextBox.Text
			Command:FireServer(text)
		end
	end)

You can use the GetPropertyChangedSignal property.

Console.MainFrame.ConsoleFrame.TextBox:GetPropertyChangedSignal("Text"):Connect(function()
	--code
end)

Oh wait, i though you can’t use GetPropertyChangedSignal on textBox? As i remember text was empty until player clicked enter or stopped focus

Can be used for all Instance and it works. Docs: Instance | Documentation - Roblox Creator Hub


whar

Console.MainFrame.ConsoleFrame.TextBox:GetPropertyChangedSignal("Text"):Connect(function()
			local text = console.MainFrame.ConsoleFrame.TextBox.Text
			pairs(text)
		--Command:FireServer(text)
	end)

Maybe print?

Console.MainFrame.ConsoleFrame.TextBox:GetPropertyChangedSignal("Text"):Connect(function()
	local text = console.MainFrame.ConsoleFrame.TextBox.Text
	print(text)
	--Command:FireServer(text)
end)```

Oh wait i’m blind and dumb lol, forget about that. Yeah it seems to work atm, let me try implementing that command system ig.

There’s no solid answer for this, basically you have to create a set of rules for predicting the command. Here’re some thoughts that may help you figure out what you’re asking for:

  1. Ignore certain differences like uppercase/lowercase when searching for commands? If so then you should check functions like string.lower and string.upper, also string.gsub might help if you want to ignore spaces or other weird characters.
  2. Do you want to check if the command starts with your input, or your input exists in the command? Basically if you type “re” are you looking for commands that start with “re” or for commands that have “re” anywhere in them. You may want to check string.find.
  3. Do you have aliases for your commands? If so should you also search for those?
  4. How should you sort the outputs if they’re more than one? Do it based on how much they match the input or also other rules like if they start with the input or the input is just in them(point 2).
  5. Do you want to autocomplete the text or show a list to the user of all the possible commands? If you want to autocomplete then you should autocomplete with the best possible match according to your sort function.

In general, the main idea is that you apply some form of preprocessing to the input(for example convert it to lowercase, remove spaces, etc) and then loop through all your command names/aliases and check if a condition is true between the input and the current command name/alias and if so then add it to a table. Then at the end sort the table according to what matches the input better and return the results sorted, then if you want a single result simply chose the best match.

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.