Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Lua search/find function

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
usernotfound
Expert Cheater
Reputation: 0

Joined: 21 Feb 2016
Posts: 115

PostPosted: Fri Feb 17, 2017 12:41 pm    Post subject: Lua search/find function Reply with quote

How can I implement a search function for a large list, i.e. with an editbox to input the keyword to search for and a list that populated only the matched items by caption?

edit: To clarify better I'm basically trying to do something like this

Back to top
View user's profile Send private message
Zanzer
I post too much
Reputation: 126

Joined: 09 Jun 2013
Posts: 3278

PostPosted: Fri Feb 17, 2017 6:01 pm    Post subject: Reply with quote

Code:
local list_of_items = {
  "Red Apple",
  "Orange Carrot",
  "Red Pepper"
}

local string_to_find = "Red"
local new_list = {}
for i, v in ipairs(list_of_items) do
  if v:find(string_to_find) then
    table.insert(new_list, v)
  end
end

print("Found:")
for i, v in ipairs(new_list) do
  print("  "..v)
end
Back to top
View user's profile Send private message
usernotfound
Expert Cheater
Reputation: 0

Joined: 21 Feb 2016
Posts: 115

PostPosted: Fri Feb 17, 2017 6:14 pm    Post subject: Reply with quote

Awesome thank you yet again Zanzer, much easier to sort through lists this way
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites