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 


two usefull functions shared

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

Joined: 10 Feb 2018
Posts: 40

PostPosted: Sun Mar 04, 2018 9:11 am    Post subject: two usefull functions shared Reply with quote

this is a function that removes duplicate members in an array

Code:

--lua 去重复,吃尾算法,OK
function (Array)--OK
for i=1,#Array  do
   for j=#Array,1,-1 do
      if i==j then
      table.remove(Array,j)
      end
   end
end
end




Add different members to the array

Code:

--添加不重复的数组成员,OK
function insert(Array,m_body)
for i=1,#Array do
if i==m_body then
return
end
end
table.insert(Array,m_body)

end



they are simple ,but usefull

_________________
A wild programmer
Back to top
View user's profile Send private message
FreeER
Grandmaster Cheater
Reputation: 31

Joined: 09 Aug 2013
Posts: 757

PostPosted: Sun Mar 04, 2018 11:48 am    Post subject: Reply with quote

This is where you can use metatables to create a "Set" type object instead of just a table/array if you need it to work for other functions that don't know about it in the same way as any other table/array. That way instead of remembering to use the insert function it's just automatically used when a newindex is created (and you can also make it so that it checks that changing values for existing indexes doesn't introduce duplicates). It can become a bit more complicated to set up (see https://gist.github.com/TannerRogalsky/8511136 and https://github.com/wscherphof/lua-set/blob/master/src/Set/init.lua) but it covers more cases.

Or if it's only your code that uses it then use the method https://www.lua.org/pil/11.5.html mentions, which is to just use the indices.

_________________
https://github.com/FreeER/ has a few CE related repos
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