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 


Script stays active after memrec.Active = false

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

Joined: 27 Jul 2013
Posts: 103

PostPosted: Fri Nov 05, 2021 7:53 pm    Post subject: Script stays active after memrec.Active = false Reply with quote

Hi experts!
I got this issue that i cannot solve, what im trying to do is stop a script when the process is not found, let's say it's a game, and the game crashed, the script should stop, but it doesn't, maybe im looking at this the wrong way.


Code:
[ENABLE]
{$lua}
tmer = createTimer(nil, false)
tmer.OnTimer = function(timer)
local proc = getProcessIDFromProcessName('process.exe')
if proc ~= nil then
--print("process.exe Found")
--============================================================
--Doing stuff
--============================================================
else
    print("Script - process.exe NOT Found")
    memrec.Active = false
    --break
end
end
tmer.Interval = 300
tmer.Enabled = true
--============================================================
{$asm}
[DISABLE]
{$lua}
tmer.Enabled = false
tmer.Destroy()


I thought this would print that the process was not found, (once) and disable the script (which it does, at least it unckecks it), stopping the "does the process exist"check, but it keeps printing that the process was not found.
Im confused, as i thought unchecking the script would stop it all.


Last edited by careca777 on Tue Nov 09, 2021 3:38 pm; edited 2 times in total
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 184

Joined: 25 Jan 2006
Posts: 8372
Location: 127.0.0.1

PostPosted: Fri Nov 05, 2021 8:34 pm    Post subject: Reply with quote

Setting the memrec from inside the Lua script does not cause the 'DISABLE' part of the script to execute. So you need to destroy the timer yourself in the 'ENABLE' section as well after setting the memrec.Active to false.
_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
careca777
Expert Cheater
Reputation: 0

Joined: 27 Jul 2013
Posts: 103

PostPosted: Mon Nov 08, 2021 9:32 pm    Post subject: Reply with quote

Hi, i tried your solution, unfortunately, when the game closes i still get a loop of "process.exe NOT Found" messages and the entries do not uncheck.
I was thinking that maybe one solution could be to force a detatch from the target process, is this even possible? i did not find any code for it in the lua page: https://wiki.cheatengine.org/index.php?title=Lua
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 422

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

PostPosted: Tue Nov 09, 2021 12:46 am    Post subject: Reply with quote

Add a check to see if the lua code is being syntaxchecked or not

Code:

if syntaxcheck then return end


else when you edit the script you're creating the tmer

_________________
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
LeFiXER
Grandmaster Cheater
Reputation: 5

Joined: 02 Sep 2011
Posts: 537
Location: 0x90

PostPosted: Tue Nov 09, 2021 4:41 am    Post subject: Reply with quote

This will disable the timer if the process isn't found. I believe setting the interval to 300ms would be too slow for it to detect if the process is there fast enough.

Code:

[ENABLE]
{$lua}
-- Initial settings for the timer
tmer = createTimer(getMainForm())
tmer.Interval = 20
tmer.OnTimer = function()
                 local proc = getProcessIDFromProcessName('process.exe')
                 if proc == nil then
                   print("Script - process.exe NOT Found")
                   tmer.Destroy()
                   tmer = nil
                   memrec.Active = false
                  else
                    -- Process found
                  end
               end

{$asm}
[DISABLE]
{$lua}
if tmer then
  tmer.destroy()
  tmer = nil
end
Back to top
View user's profile Send private message
careca777
Expert Cheater
Reputation: 0

Joined: 27 Jul 2013
Posts: 103

PostPosted: Tue Nov 09, 2021 11:10 am    Post subject: Reply with quote

Dark Byte wrote:
Add a check to see if the lua code is being syntaxchecked or not

Code:

if syntaxcheck then return end


else when you edit the script you're creating the tmer


Thank you for the suggestion.
There was no change, scripts did not uncheck by themselves as they detect that the process doesnt exist. Manually unchecking also did nothing, it's like it keeps looping regardless of what i do, only way to stop is closing CE.

@LeFIXER: if i tighten the loop up, it causes issues because of load, stutters and such. Regardless of this, i don't see how tightening the loop would make a difference, with a larger timer when eventualy the loop checks for the process and it is not found, it should disable the timer and uncheck the entry, and it doesn't. Have no idea why.
Back to top
View user's profile Send private message
LeFiXER
Grandmaster Cheater
Reputation: 5

Joined: 02 Sep 2011
Posts: 537
Location: 0x90

PostPosted: Tue Nov 09, 2021 1:01 pm    Post subject: Reply with quote

careca777 wrote:

@LeFIXER: if i tighten the loop up, it causes issues because of load, stutters and such. Regardless of this, i don't see how tightening the loop would make a difference, with a larger timer when eventualy the loop checks for the process and it is not found, it should disable the timer and uncheck the entry, and it doesn't. Have no idea why.


Perhaps the interval of the timer isn't an issue. Nevertheless, the code I provided prints to the console if the process isn't found and subsequently destroys the timer. In your initial submission there wasn't a check to see if the timer exists upon disabling and asks Cheat Engine to destroy it anyway which is bad. You can't set something to nil if it doesn't exist.
Back to top
View user's profile Send private message
careca777
Expert Cheater
Reputation: 0

Joined: 27 Jul 2013
Posts: 103

PostPosted: Tue Nov 09, 2021 2:03 pm    Post subject: Reply with quote

That makes sense, i didn't notice it.
Thanks, will try.

EDIT: That was the issue indeed, it now unchecks and does not throw errors at all.
Many thanks! Smile

EDIT2: So, i needed to change
tmer = createTimer(nil, false)
to true, or it wouldn't do anything, other than that seems to be ok.
Back to top
View user's profile Send private message
LeFiXER
Grandmaster Cheater
Reputation: 5

Joined: 02 Sep 2011
Posts: 537
Location: 0x90

PostPosted: Tue Nov 09, 2021 8:02 pm    Post subject: Reply with quote

careca777 wrote:
That makes sense, i didn't notice it.
Thanks, will try.

EDIT: That was the issue indeed, it now unchecks and does not throw errors at all.
Many thanks! Smile

EDIT2: So, i needed to change
tmer = createTimer(nil, false)
to true, or it wouldn't do anything, other than that seems to be ok.


I would also set the owner to Cheat Engine to prevent any memory leaks. i.e.:
Code:

-- getMainForm() returns the handle to the Cheat Engine main window.
local owner = getMainForm()
tmr = createTimer(owner, false)
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