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 


How to improve the code and use less memory?

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

Joined: 17 Jan 2018
Posts: 205

PostPosted: Mon Sep 30, 2019 5:11 am    Post subject: How to improve the code and use less memory? Reply with quote

Is there a way to improve the following code?
Do I need to use caFree in the all Close events?
Also CE display errors when I close ePSXe, how to get rid of them?

Code:

GameName1 = 'ePSXe ENG.exe'
GameName2 = 'ePSXe.exe'
GameID1 = getProcessIDFromProcessName(GameName1)
GameID2 = getProcessIDFromProcessName(GameName2)
if (GameID1 == nil) and (GameID2 ~= nil) then
openProcess(GameName2)
elseif (GameID1 ~= nil) and (GameID2 == nil) then
openProcess(GameName1)
elseif (GameID1 == nil) and (GameID2 == nil) then
closeCE()
return end

  MenuIt[7].OnClick = function(sender111)
  closeCE()
  end

  MenuIt[11].OnClick = function(sender)
  closeCE()
  end

  function CloseClick()
  closeCE()
  return caFree
  end

timer = createTimer(nil,false)
timer.Interval = 1000

trtimesecCounter = 0
-- OnTimer
counterUsedForGC = 0
timer.OnTimer = function()

  GameID1 = getProcessIDFromProcessName(GameName1)
  GameID2 = getProcessIDFromProcessName(GameName2)
  if (GameID1 == nil) and (GameID2 == nil) then
  closeCE()
  return end

   trtimesecCounter = trtimesecCounter + 1
   Trtime[1].Caption = trtimesecCounter % 60
   Trtime[2].Caption = (trtimesecCounter % 3600) // 60
   Trtime[3].Caption = trtimesecCounter // 3600

   if trtimesecCounter % 60 < 10 then
   timeadd0[4].Caption = '0'
   else
   timeadd0[4].Caption = ''
   end

   if (trtimesecCounter % 3600) // 60 < 10 then
   timeadd0[3].Caption = '0'
   else
   timeadd0[3].Caption = ''
   end

  counterUsedForGC = counterUsedForGC + 1
  if counterUsedForGC>59 then collectgarbage("collect"); counterUsedForGC = 0 end  -- every 60 ticks

end
-- enable timer
timer.Enabled = true
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 470

Joined: 09 May 2003
Posts: 25791
Location: The netherlands

PostPosted: Mon Sep 30, 2019 7:38 am    Post subject: Reply with quote

before calling closeCE execute
Code:

if timer then timer.destroy() timer=nil end

_________________
Do not ask me about online cheats. I don't know any and wont help finding them.

Like my help? Join me on Patreon so i can keep helping
Back to top
View user's profile Send private message MSN Messenger
Razi
Expert Cheater
Reputation: 1

Joined: 17 Jan 2018
Posts: 205

PostPosted: Mon Sep 30, 2019 10:57 am    Post subject: Reply with quote

Thanks. Does timer.destroy() need to be added only to the timer event or to MenuItem.OnClick and UDF1.OnClose too?
Does caFree need to be added to MenuItem.OnClick events?
Code:
MenuIt[11].OnClick = function(sender)
  closeCE()
  end
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