| View previous topic :: View next topic |
| Author |
Message |
careca777 Expert Cheater
Reputation: 0
Joined: 27 Jul 2013 Posts: 121
|
Posted: Thu Jan 14, 2021 5:10 pm Post subject: Trying to create a loop "freezes" application |
|
|
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 |
|
 |
ParkourPenguin I post too much
Reputation: 152
Joined: 06 Jul 2014 Posts: 4711
|
Posted: Thu Jan 14, 2021 5:34 pm Post subject: |
|
|
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 |
|
 |
Dark Byte Site Admin
Reputation: 471
Joined: 09 May 2003 Posts: 25818 Location: The netherlands
|
Posted: Thu Jan 14, 2021 5:48 pm Post subject: |
|
|
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 |
|
 |
careca777 Expert Cheater
Reputation: 0
Joined: 27 Jul 2013 Posts: 121
|
Posted: Fri Jan 15, 2021 2:59 pm Post subject: |
|
|
@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 |
|
 |
ParkourPenguin I post too much
Reputation: 152
Joined: 06 Jul 2014 Posts: 4711
|
Posted: Fri Jan 15, 2021 4:11 pm Post subject: |
|
|
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 |
|
 |
careca777 Expert Cheater
Reputation: 0
Joined: 27 Jul 2013 Posts: 121
|
Posted: Fri Jan 15, 2021 4:14 pm Post subject: |
|
|
| 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 |
|
 |
Dark Byte Site Admin
Reputation: 471
Joined: 09 May 2003 Posts: 25818 Location: The netherlands
|
Posted: Fri Jan 15, 2021 4:43 pm Post subject: |
|
|
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 |
|
 |
careca777 Expert Cheater
Reputation: 0
Joined: 27 Jul 2013 Posts: 121
|
Posted: Fri Jan 15, 2021 5:21 pm Post subject: |
|
|
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 |
|
 |
Dark Byte Site Admin
Reputation: 471
Joined: 09 May 2003 Posts: 25818 Location: The netherlands
|
Posted: Fri Jan 15, 2021 5:41 pm Post subject: |
|
|
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 |
|
 |
careca777 Expert Cheater
Reputation: 0
Joined: 27 Jul 2013 Posts: 121
|
Posted: Fri Jan 15, 2021 6:57 pm Post subject: |
|
|
Placing it under OnTimer did the trick!
Many thanks! |
|
| Back to top |
|
 |
careca777 Expert Cheater
Reputation: 0
Joined: 27 Jul 2013 Posts: 121
|
Posted: Wed Jan 20, 2021 12:26 pm Post subject: |
|
|
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 |
|
 |
Dark Byte Site Admin
Reputation: 471
Joined: 09 May 2003 Posts: 25818 Location: The netherlands
|
Posted: Wed Jan 20, 2021 12:32 pm Post subject: |
|
|
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 |
|
 |
|