Hi, basically what I want is a system where the player can insert part of a word into a textbox and when submitted it will find the part in a folder that is the closest match. For example… I put ‘Au’ and in the folder there is ‘Angle’, ‘Automobil’ and ‘Cheese’. Even though they haven’t got the full word I want it to match. Any ideas on how I could do this???
I think the function below is useful:
string.match(PartName, TextToFind)
1 Like
What if I have multiple words to check though?
You should also change the string to capital letters.
1 Like
You can have a system that takes the TextBox text at face value and then match it up to a folder using string.find
, something like this:
local text = string.lower(script.Parent.Text)
for i,folder in pairs(folders) do
if string.find(string.lower(folder.Name),text) then
-- match found
end
end
Alternatively for a more complex system you can split each string up by it’s letters and assign each a sort of “value” based on how many letters it matches to the TextBox’s text (excuse the poor scripting ahead, wrote it on the fly without much thought)
function FindMatch(text)
local text = string.lower(text)
local folders = {"Hi1","Hi2","Goodbye"}
local values = {}
for i,folder in pairs(folders) do
local tbl = {}
local val = 0
local name = string.lower(folder)
for i = 1,#name do
table.insert(tbl,#tbl+1,string.sub(name,i,i))
end
for _,letter in pairs(tbl) do
if string.find(text,letter) then
val = val+1
end
end
values[folder] = val
end
local mfolder,match = "",0
for folder,value in pairs(values) do
if value > match then
mfolder = folder
match = value
end
end
return mfolder
end
print(FindMatch("g"))
Where “mfolder” is a string that holds the name of the folder it found, and “match” is a placeholder integer that has no relevance outside of determining the match.