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 


Trying to create a loop "freezes" application

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

Joined: 27 Jul 2013
Posts: 121

PostPosted: Thu Jan 14, 2021 5:10 pm    Post subject: Trying to create a loop "freezes" application Reply with quote

Hi experts, im using this code, attempting to create a loop with a delay of 1 sec. or so, but when i paste this in the script window the ok button doesnt do anything, and there are no error messages at all, furthermore, i cannot close the window, even if i delete all the code! The only way to close the window from there on, is by force closing the application.
I know im probably doing some script errors, but this never happened before, it would always give me some error message.

Code:
[ENABLE]
//[ammocurrweapon]+20:
{$lua}
repeat
local timer = createTimer(getMainForm())
timer.Interval = 1000
timer.OnTimer = function(timer)
  local addr = getAddress"[ammocurrweapon]+20",true
  writeInteger(addr, 999)
  if DoneState == true then
    timer.destroy()
  end
end
until false
{$asm}
[DISABLE]


Thanks in advance.
Back to top
View user's profile Send private message
ParkourPenguin
I post too much
Reputation: 152

Joined: 06 Jul 2014
Posts: 4711

PostPosted: Thu Jan 14, 2021 5:34 pm    Post subject: Reply with quote

Indent your code correctly.
Code:
repeat
  local timer = createTimer(getMainForm())
  timer.Interval = 1000
  timer.OnTimer = function(timer)
    local addr = getAddress"[ammocurrweapon]+20",true
    writeInteger(addr, 999)
    if DoneState == true then
      timer.destroy()
    end
  end
until false

The ",true" at the end of getAddress is useless.

_________________
I don't know where I'm going, but I'll figure it out when I get there.
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 471

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

PostPosted: Thu Jan 14, 2021 5:48 pm    Post subject: Reply with quote

also the timer will never execute it's code as long as the repeat until false runs, which will execute forever as nothing is stopping it
_________________
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
careca777
Expert Cheater
Reputation: 0

Joined: 27 Jul 2013
Posts: 121

PostPosted: Fri Jan 15, 2021 2:59 pm    Post subject: Reply with quote

@ParkourPenguin: Thank you, i didn't realize indentation was important. Will change and try.

@DarkByte: Thank you, I thought of it as pausing at each cycle if you know what i mean.
How can i (or should i) add a small pause, as you do in other languages, to not overload the cpu?
I tried the "wait(1000)" but as it says on wiki, it freezes the whole main GUI.
Back to top
View user's profile Send private message
ParkourPenguin
I post too much
Reputation: 152

Joined: 06 Jul 2014
Posts: 4711

PostPosted: Fri Jan 15, 2021 4:11 pm    Post subject: Reply with quote

By indenting your code, I was trying to point out you've created a loop that never terminates. You're just creating timers endlessly. If you don't know what repeat...until does, look it up.

I don't know what you're trying to do, but removing the outside loop would certainly be a step in the right direction.

_________________
I don't know where I'm going, but I'll figure it out when I get there.
Back to top
View user's profile Send private message
careca777
Expert Cheater
Reputation: 0

Joined: 27 Jul 2013
Posts: 121

PostPosted: Fri Jan 15, 2021 4:14 pm    Post subject: Reply with quote

Well, the loop is supposed to last until i close the application, in order to continuously update [ammocurrweapon], else, i need to go in and enable the script anytime i need updated values.
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 471

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

PostPosted: Fri Jan 15, 2021 4:43 pm    Post subject: Reply with quote

instead of a loop, use a timer that repeats every few milliseconds
_________________
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
careca777
Expert Cheater
Reputation: 0

Joined: 27 Jul 2013
Posts: 121

PostPosted: Fri Jan 15, 2021 5:21 pm    Post subject: Reply with quote

This is what i ended up with:

Code:
[ENABLE]
{$lua}
if syntaxcheck then return end
local addr = getAddress"[ammocurrweapon]+20",true
writeInteger(addr, 999)
tmer = createTimer(nil, false)
tmer.OnTimer = function(timer)
  writeInteger(addr, 999)
end
tmer.Interval = 1000
tmer.Enabled = true
{$asm}
[DISABLE]


No idea how to turn off, or why it sometimes stop updating the ammo when i change to some weapons, but the pointer shows the ammo accurately.
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 471

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

PostPosted: Fri Jan 15, 2021 5:41 pm    Post subject: Reply with quote

because you only get the address of [ammocurrweapon]+20 once

so if at the time the addresss of [ammocurrweapon]+20 is 12345678

then the writeInteger(addr,999) in the timer will be constantly writing to 12345678 even if [ammocurrweapon]+20 has changed to something else

So place the getAddress in the timer's OnTimer

Or do:
Code:

[ENABLE]
local r=AddressList['DescriptionOfRecordWithAmmo']
r.Active=true
r.Value=999
[DISABLE]
AddressList['DescriptionOfRecordWithAmmo'].Active=false

_________________
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
careca777
Expert Cheater
Reputation: 0

Joined: 27 Jul 2013
Posts: 121

PostPosted: Fri Jan 15, 2021 6:57 pm    Post subject: Reply with quote

Placing it under OnTimer did the trick!

Many thanks!
Back to top
View user's profile Send private message
careca777
Expert Cheater
Reputation: 0

Joined: 27 Jul 2013
Posts: 121

PostPosted: Wed Jan 20, 2021 12:26 pm    Post subject: Reply with quote

Hi fellas, turns out an issue came up when trying to set a condition.
When i use just the ammo code by itself, while ammo is less than 10, it works, but when i incorporate the code with the timer, to loop it as discussed here, it doesn't do anything.

Code:
[ENABLE]
{$lua}
if syntaxcheck then return end
tmer = createTimer(nil, false)
tmer.OnTimer = function(timer)
--============================================================
  local currweapon = getAddress"[ammocurrweapon]+20" --Ammo
  if readInteger(currweapon) < 10 then
     writeInteger(currweapon, 100)
  end
--============================================================
  tmer.Interval = 1500
  tmer.Enabled = true
end
{$asm}
[DISABLE]


Im very confused, maybe something was deleted when modifying the code!?

Thanks in advance.

EDIT: Nevermind, fixed when i noticed the "end" was in the wrong place.
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 471

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

PostPosted: Wed Jan 20, 2021 12:32 pm    Post subject: Reply with quote

I've indented your code. Perhaps it'll show you the issue.

(tip: createTimer(nil, false) tells it to create a timer that is currently not enabled)

edit: Seems you found it

_________________
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
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General Gamehacking 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