|
Cheat Engine The Official Site of Cheat Engine
|
View previous topic :: View next topic |
Author |
Message |
izytang How do I cheat? Reputation: 2
Joined: 07 Feb 2022 Posts: 7 Location: Columbus, OH
|
Posted: Thu Aug 31, 2023 9:16 pm Post subject: Global "Killswitch" to disable and halt all runnin |
|
|
This seems a like basic question, but I've searched long on forums, Google, documentation, and even ChatGPT. How do you disable, halt, turn off, or otherwise stop all lua scripts currently running in the background of Cheat Engine?
The only solutions I can seem to find is to run more scripts that target existing scripts (example: t.destroy() for timers). But is there a global killswitch that terminates all running scripts? I'm not seeing anything in CT's GUI for a pause/stop button, be it the lua scripting window, lua engine/output window, other menus, or know of any executable commands.
Specific to my problem, I'm testing some hotkey functionality in lua in order to execute inventory replacement and item stocking. This is more complicated than the simple freeze/toggle/increment functions within the address view Change/Set Hotkey settings. Thus the need to run a lua script - and then trigger by hotkey. But now I have multiple test functions still running from those hotkeys - how can I disable all scripts running and start clean?
While there might be something to that specific issue of hotkey scripts, I've run into this on multiple projects. Usually I have to find code to run to disable the script, or, quit CT and restart. But is there a general terminate for all scripts?
It feels silly and basic that I might be missing something fundamental, but I cannot find the answer anywhere. If such a killswitch doesn't exist, would a feature request be in order?
EDIT:
And for context on my specific issue, here's the lua code:
Code: |
function performSearchAndReplace()
-- does nothing, yet
print('hello world')
end
hkey = createHotkey("performSearchAndReplace", VK_Z)
generichotkey_onHotkey(hkey,performSearchAndReplace)
|
Again, just skeleton code to test out the functions. However, I executed it a few times without destroying the hkey object. When I run "hotkey.destroy()" in the output window's console, it gets rid of the most recent script, but not the others (also named hkey).
Importantly, I'm just looking for a general "kill all scripts" button or command, as I've run into this same issue with other objects and functions. It'd be great and convenient for testing and debugging, without having to keep track of each created object. Naturally, code should be cleaned up with proper garbage collection, but it would be nice to have a scripting sandbox to test things - along with the "reset sand" ability.
|
|
Back to top |
|
|
ParkourPenguin I post too much Reputation: 140
Joined: 06 Jul 2014 Posts: 4307
|
Posted: Fri Sep 01, 2023 10:06 am Post subject: |
|
|
The fundamental issue here is that scripts don't continue running after they exit. Objects you create in the script persist after the script has finished.
When you execute this script: Code: | hk = createHotkey(...) | A hotkey is created and the script exists successfully. The script did what it was suppose to do: it created a hotkey and stopped running.
Execute that script again and it will do the exact same thing again: create another hotkey and exit successfully. The first hotkey still exists.
If you don't want the first hotkey to still exist, either destroy it or reuse it. (use global variables)
Code: | if hk then hk.destroy(); hk = nil end
hk = createHotkey(...) |
Code: | if not hk then
hk = createHotkey(...)
end
hk.onHotkey = function() ... end |
You could also hook createHotkey to manage all the hotkeys created using it.
_________________
I don't know where I'm going, but I'll figure it out when I get there. |
|
Back to top |
|
|
izytang How do I cheat? Reputation: 2
Joined: 07 Feb 2022 Posts: 7 Location: Columbus, OH
|
Posted: Fri Sep 01, 2023 11:32 am Post subject: |
|
|
Thank you for the clarification of the internal structure of scripts and objects. To refine my question: How does one terminate all objects persisting in the background?
There are cases where I might be sandboxing, creating random objects. Is there a way to destroy all objects simultaneously? Or if not, and it has to be done with more script, is there a way to list all existing objects? I run into situations where there might be multiple randomly named objects from sandboxing, and if I don't remember all the names, there's no way to see them all.
As for my specific scenario with the hotkey handling, I did already try to destroy the object and make it nil. It did get rid of the most recently created object, but the ones created before that (under the same name) still persist. I'm guessing the objects have moved in a stack or something in the background? How can I access those?
To clarify, here's an example layout of the problem I'm facing:
Keyboard assigned key: Z
1st hkey created: print "test 1"
2nd hkey created: print "test 2"
3rd hkey created: print "test 3"
Now when I press "Z", it outputs "test 1", "test 2" and "test 3". When I destroy and nil hkey and press the key, it outputs "test 1" and "test 2". It got rid of the most recent hkey object (that printed "test 3"). If I destroy and nil hkey again, nothing new happens. I can't seem to do anything about the 1st and 2nd hkey objects created. How could I access those?
Ultimately, a global object killswitch would make the whole problem nil (pun intended). Does such a method exist?
|
|
Back to top |
|
|
ParkourPenguin I post too much Reputation: 140
Joined: 06 Jul 2014 Posts: 4307
|
Posted: Fri Sep 01, 2023 12:19 pm Post subject: |
|
|
You explained things perfectly well in your first post. What I said in the second post is the best way of resolving your problem. I neglected to mention that the solution you want doesn't really exist.
izytang wrote: | How does one terminate all objects persisting in the background? | Restart CE. Seriously- if you're playing around, the best thing you can do is to open a new instance of CE that could crash or be closed at any point in time without any significant loss of work.
There isn't any good way of doing that from Lua while CE is running. You can hook object creation functions and keep references to them in a table, but that's a little annoying.
izytang wrote: | As for my specific scenario with the hotkey handling, I did already try to destroy the object and make it nil. It did get rid of the most recently created object, but the ones created before that (under the same name) still persist. I'm guessing the objects have moved in a stack or something in the background? How can I access those? | No, they aren't moved into a stack. When all variables referencing an object is gone, the object is simply leaked. There's no way to access them from Lua.
IIRC some types of objects get automatically destroyed when the Lua userdata gets garbage collected, but I'd be very surprised if hotkeys or timers acted that way.
If you destroyed or reused the objects since the beginning, you wouldn't have this problem. Just follow that pattern in the previous post for every timer/hotkey you make and you'll be fine.
izytang wrote: | Keyboard assigned key: Z
1st hkey created: print "test 1"
2nd hkey created: print "test 2"
3rd hkey created: print "test 3"
Now when I press "Z", it outputs "test 1", "test 2" and "test 3". When I destroy and nil hkey and press the key, it outputs "test 1" and "test 2". | 1st hotkey- add these two lines of code to the script:
Code: | if hk then hk.destroy(); hk = nil end
hk = createHotkey(function() print'test 1' end, VK_Z) | 2nd hotkey- change "1" to "2":
Code: | if hk then hk.destroy(); hk = nil end
hk = createHotkey(function() print'test 2' end, VK_Z) | 3rd hotkey- change "2" to "3":
Code: | if hk then hk.destroy(); hk = nil end
hk = createHotkey(function() print'test 3' end, VK_Z) | Press 'z' now, it only prints "test 3".
Destroy the hotkey- commenting out the second line of code is the fastest way:
Code: | if hk then hk.destroy(); hk = nil end
--hk = createHotkey(function() print'test 3' end, VK_Z) | Press 'z' now, it does nothing.
Add that one line of code when you first start and save yourself the headache of restarting CE every time you accidentally leak an object.
_________________
I don't know where I'm going, but I'll figure it out when I get there. |
|
Back to top |
|
|
izytang How do I cheat? Reputation: 2
Joined: 07 Feb 2022 Posts: 7 Location: Columbus, OH
|
Posted: Fri Sep 01, 2023 1:39 pm Post subject: |
|
|
Thank you for all this detailed and valuable information. I've since implemented object handling now that I know I need to be more conscious about it.
Normally in the past, I had just restarted CE. But in this instance, I had done a bunch of memory/address scans and hadn't yet gone through the pointer mapping to get all the base addresses. In order to proceed, I had to use CE without pressing the hotkeys, but if were a timer constantly printing to the output window, CE would be unusable, and I'd lose all my work. Basically, a simple sandboxing session sometimes turns into a whole mini-project, without going through a normal workflow.
Seems the central issue is the prevalence of leaked objects, which I suspect is beyond the scope of Lua and more of an issue with Cheat Engine itself. I'm guessing this bug fix had already been requested, but it'd be great to update Cheat Engine to address these object/memory leaks. Further, I'd like to put in a feature request for the following:
1. A GUI implementation to view and manage all running objects from Lua/AA.
2. A global killswitch for all objects and event handlers, maybe as a "Terminate" button in the Lua Engine window (or similar).
And if there's a person/place that the feature request needs to be formally sent to, feel free to link that. Thanks for clearing things up!
|
|
Back to top |
|
|
ParkourPenguin I post too much Reputation: 140
Joined: 06 Jul 2014 Posts: 4307
|
Posted: Fri Sep 01, 2023 3:09 pm Post subject: |
|
|
izytang wrote: | I suspect is beyond the scope of Lua and more of an issue with Cheat Engine itself. I'm guessing this bug fix had already been requested, but it'd be great to update Cheat Engine to address these object/memory leaks. | The issue is probably that Lua is a higher level scripting language trying to be used as a lower level programming language. There's going to be a few rough spots.
Leaking objects isn't a bug. Any "fix" I can think of would be worse than the current behaviour.
A GUI that controls timers and hotkeys would be good, but that's more suited for a Lua extension than something built into CE.
_________________
I don't know where I'm going, but I'll figure it out when I get there. |
|
Back to top |
|
|
Dark Byte Site Admin Reputation: 458
Joined: 09 May 2003 Posts: 25300 Location: The netherlands
|
Posted: Sat Sep 02, 2023 11:59 pm Post subject: |
|
|
Just read the manual.
If something creates an object, you often have to manually destroy it
Even a simple createStringList() requires a .destroy() afterwards
And you can't just kill all timers, some timers are needed like the garbage collector, addresslist updater, foundlist updater, etc...
Just keep track of objects you have created
As for getting lots of prints, adjust that script that's causing those prints. Give the timer a selfdestruct when a certain value is set, or just destroy the timer yourself
If your issue is with the popup of the window you can do view->show on print to turn that off
Also, don't use the same global variable for different things
_________________
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 |
|
|
|
|
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
|
|