How do you filter out when you type?

Hey there. I’m Drinkinix. I’ve been working on this inventory system for my game, and I’m stumped on this one thing.

I’ve been wondering how I could type in certain words, and as I type, the words filter out and show all the words that go into that category. For example, if I type:

H, then it’ll filter until there are all H words, and so forth.

Help would be very much appreciated, and my apologies if this topic was hard to understand.

– Drinkinix :slightly_smiling_face:

1 Like

You can use string.match for it.

You can use it like this.

local word = string.match("Welcome to Roblox!", "Roblox") 
if word ~= nil then
--Do stuff
end

Now let me explain it in argument 1 we gave the string and in the second argument we gave the word we are looking for. If the script finds the word it will return “Roblox” but if the script can’t find it it will return nil.
Sorry if it is wrong. It is 1 A.M and I am sleepy :sleeping:

2 Likes

Check out the string library

1 Like

Do you mean that for example this is your inventory:

golden sword
golden axe
gray coat
diamond pickaxe

And when you type in g you get

golden sword
golden axe
gray coat

and when you add o so you have typed “go” you get

golden sword
golden axe

Then it can be done like that:

  1. Inventory has an index of all items inside that is sorted by name, for example our index will look like that

diamond pickaxe
golden axe
golden sword
gray coat

  1. When you add an item to the inventory you also have to put it at the correct place in the ‘index’.
  2. When you remove an item you simply remove it from the index too.
  3. When you start typing in the letters I prefer to use Binary Search algorithm to find all the words that start with the letters we typed in (that’s why the index has to be an ordered index). This is fast and efficient.
2 Likes