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 


Manually Stop Thread

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
Suuper
How do I cheat?
Reputation: 0

Joined: 18 Jul 2015
Posts: 5

PostPosted: Sat Jul 18, 2015 9:56 pm    Post subject: Manually Stop Thread Reply with quote

I have a Lua script which runs an infinite loop in a separate thread, but I want to be able to manually stop that thread.

Is there a way to do this, besides something like closing CE?
Back to top
View user's profile Send private message
Daijobu
Master Cheater
Reputation: 13

Joined: 05 Feb 2013
Posts: 301
Location: the Netherlands

PostPosted: Sun Jul 19, 2015 12:16 am    Post subject: Reply with quote

Can we see your code or pseudocode?

You can use a toggle, set up a variable and check it every time it loops to be true. If not true then continue loop.
If true (manually) loop will exit.

_________________
Scripts/tables from scratch. Relation to other scripts is coincidental. Use of posted code is credited properly.
Euro Truck Simulator 2 Backwards Compatible Cheat
American Truck Simulator Backwards Compatible Cheat
Back to top
View user's profile Send private message
Suuper
How do I cheat?
Reputation: 0

Joined: 18 Jul 2015
Posts: 5

PostPosted: Sun Jul 19, 2015 1:18 pm    Post subject: Reply with quote

Here's how I have the infinite loop set up:

Code:
function doWork()
    --Do some stuff
    while (true) do
        --Do more stuff
    end
end

createNativeThread(doWork);
Back to top
View user's profile Send private message
Zanzer
I post too much
Reputation: 126

Joined: 09 Jun 2013
Posts: 3278

PostPosted: Sun Jul 19, 2015 1:32 pm    Post subject: Reply with quote

Wow, that must be killing your CPU. Smile

Does this work?
Code:
[ENABLE]
${lua}
KEEP_GOING = true
function doWork()
    --Do some stuff
    while (KEEP_GOING) do
        --Do more stuff
    end
end

createNativeThread(doWork);
{$asm}

[DISABLE]
{$lua}
KEEP_GOING = false
{$asm}
Back to top
View user's profile Send private message
Suuper
How do I cheat?
Reputation: 0

Joined: 18 Jul 2015
Posts: 5

PostPosted: Sun Jul 19, 2015 2:03 pm    Post subject: Reply with quote

Zanzer wrote:
Wow, that must be killing your CPU. Smile

Does this work?
Code:
[ENABLE]
${lua}
KEEP_GOING = true
function doWork()
    --Do some stuff
    while (KEEP_GOING) do
        --Do more stuff
    end
end

createNativeThread(doWork);
{$asm}

[DISABLE]
{$lua}
KEEP_GOING = false
{$asm}


What is {$lua/asm} and [EN/DISABLE] supposed to do? When I paste that into my script I get an error message: "unexpected symbol near '['" on the line with [ENABLE].

(@killing my CPU: Part of my "do more stuff" is using sleep, waiting for when it's supposed to actually happen.)
Back to top
View user's profile Send private message
Zanzer
I post too much
Reputation: 126

Joined: 09 Jun 2013
Posts: 3278

PostPosted: Sun Jul 19, 2015 3:45 pm    Post subject: Reply with quote

Those commands are used for Cheat Engine's table entry scripts.
If you're adding scripts elsewhere, ignore those commands.
The main part was to replace "while (true)" with a variable you can change.
You'll need to create a separate action which executes:
Code:
KEEP_GOING = false
Back to top
View user's profile Send private message
Suuper
How do I cheat?
Reputation: 0

Joined: 18 Jul 2015
Posts: 5

PostPosted: Mon Jul 20, 2015 10:11 pm    Post subject: Reply with quote

I got it to work using a cheat table with a form, using a button to start/stop the script.

Thanks for the helps.
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