Most optimized way to make a search button.

Yo, so i’m making a search bar for my logging system.

I have a shitty one done, i feel like it is so unoptimized, like really badly so.

Anyone got examples of searching through tables for certain things, then if they are found adding the found things to a new table.


      TextEntry.OnEnter = function( self )
      
         -- Messy code, woop
         
         table.Empty(Results)
         
         SearchResult:Clear(true) 
         
         for k,v in pairs(DeathLogs) do
            
            if string.find(v.Killer, SearchText) then
               table.insert(Results,v.Killer)
            end
            
         end
         
         for _,b in pairs(Results) do
            SearchResult:AddLine(b)
         end
          
      end
      
      TextEntry.OnTextChanged = function( self )
         SearchText = self:GetValue()      
      end


my hacky, shitty code

That looks as good as you can get without adding restrictions.
Unrelated: Remember there are [noparse][lua][/lua][/noparse] tags.

edit: Listen to PortalGod, not me

How are they different from [noparse]


 tags? Syntax highlighting seems to be identical, and I even dare say that 

[/noparse] tags achieve even more reliable results. (although that might be a misobservation on my part)

Really? When i writ it i felt like it was horrible, guess i will use this then :slight_smile:

[lua]TextEntry.OnEnter = function( self )
SearchResult:Clear(true)

for k,v in pairs(DeathLogs) do
	if string.find(v.Killer, SearchText) then
	   SearchResult:AddLine(v.Killer)
	end
end

end

TextEntry.OnTextChanged = function( self )
SearchText = self:GetValue()
end[/lua]

do you need the results table? even if you do, you can at least cut out the last for loop