View previous topic :: View next topic |
Author |
Message |
careca777 Expert Cheater Reputation: 0
Joined: 27 Jul 2013 Posts: 121
|
Posted: Fri Nov 05, 2021 7:53 pm Post subject: Script stays active after memrec.Active = false |
|
|
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 |
|
|
atom0s Moderator Reputation: 198
Joined: 25 Jan 2006 Posts: 8517 Location: 127.0.0.1
|
Posted: Fri Nov 05, 2021 8:34 pm Post subject: |
|
|
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 |
|
|
careca777 Expert Cheater Reputation: 0
Joined: 27 Jul 2013 Posts: 121
|
Posted: Mon Nov 08, 2021 9:32 pm Post subject: |
|
|
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 |
|
|
Dark Byte Site Admin Reputation: 458
Joined: 09 May 2003 Posts: 25287 Location: The netherlands
|
Posted: Tue Nov 09, 2021 12:46 am Post subject: |
|
|
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 |
|
|
LeFiXER Grandmaster Cheater Supreme Reputation: 20
Joined: 02 Sep 2011 Posts: 1055 Location: 0x90
|
Posted: Tue Nov 09, 2021 4:41 am Post subject: |
|
|
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 |
|
|
careca777 Expert Cheater Reputation: 0
Joined: 27 Jul 2013 Posts: 121
|
Posted: Tue Nov 09, 2021 11:10 am Post subject: |
|
|
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 |
|
|
LeFiXER Grandmaster Cheater Supreme Reputation: 20
Joined: 02 Sep 2011 Posts: 1055 Location: 0x90
|
Posted: Tue Nov 09, 2021 1:01 pm Post subject: |
|
|
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 |
|
|
careca777 Expert Cheater Reputation: 0
Joined: 27 Jul 2013 Posts: 121
|
Posted: Tue Nov 09, 2021 2:03 pm Post subject: |
|
|
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!
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 |
|
|
LeFiXER Grandmaster Cheater Supreme Reputation: 20
Joined: 02 Sep 2011 Posts: 1055 Location: 0x90
|
Posted: Tue Nov 09, 2021 8:02 pm Post subject: |
|
|
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!
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 |
|
|
|