View previous topic :: View next topic |
Author |
Message |
etioplmld Advanced Cheater Reputation: 0
Joined: 09 Feb 2021 Posts: 72
|
Posted: Thu May 11, 2023 12:53 am Post subject: How to wait for two seconds in each loop of Lua's for loop? |
|
|
When using the for loop to process some addresses, it is necessary to wait for each address, loop wait.
first,Define a function.
Functions like this
Set breakpoints on an address
Check if the address has been accessed until two seconds timeout
Then use the for function to execute the function for each address。
But the result of such code execution is that the for function did not wait and directly checked all addresses
|
|
Back to top |
|
|
Dark Byte Site Admin Reputation: 457
Joined: 09 May 2003 Posts: 25262 Location: The netherlands
|
Posted: Thu May 11, 2023 1:50 am Post subject: |
|
|
it's better to split up the for loop into different pieces of code and use createTimer(time,function) to create 1 time run timers
But if you insist (warning: crappy bad code here)
Code: |
local a=getApplication()
killme=false
for i=1,1000 do
print(i)
local t=getTickCount()
while getTickCount()<t+2000 do --check if 2000 milliseconds have passed
if killme then return end
a.processMessages()
end
end
|
_________________
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 |
|
|
etioplmld Advanced Cheater Reputation: 0
Joined: 09 Feb 2021 Posts: 72
|
Posted: Thu May 11, 2023 3:16 am Post subject: |
|
|
There is a lot of JavaScript code in the search results for this question. Can it be converted to Lua?
Code: |
for (var i = 0; i < 5; i++) {
(function (j) {
setTimeout(function() {
console.log(new Date, j);
}, 1000 * j);
})(i);
}
setTimeout(function() {
console.log(new Date, i);
}, 1000 * i);
|
Code: |
function time(val)
{
for(var i = val;i<7;i++)
{
alert(i)
window.setTimeout("time("+ ++i +")",1000)
break;
}
}
time(0)
|
Code: |
for (var i = 0; i < 6; i++) {
setTimeout(fn(i),1000);
}
function fn(a){
return function(){
console.log(a);
}
}
|
Code: |
for (var i = 0; i < 6; i++) {
(function (t, data) {
setTimeout(function () {
console.log(`this is ${t} times,this is other:${data}`);
}, 1000 * t);
})(i, 'other')
}
|
Code: |
for (let i = 1; i <= 5; i++) {
setTimeout(function timer() {
console.log(i);
}, i * 1000);
}
|
|
|
Back to top |
|
|
Dark Byte Site Admin Reputation: 457
Joined: 09 May 2003 Posts: 25262 Location: The netherlands
|
Posted: Thu May 11, 2023 4:08 am Post subject: |
|
|
maybe an example like this will help:
Code: |
for i=1,20 do
local uv=i*1000
createTimer(1000*i,function()
print("handling timer "..i.." uv="..uv)
end)
end
|
_________________
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 |
|
|
|