Jump to content

Timer Help


Recommended Posts

I am trying to figure out why this timer does not work. It works once then it doesn't loop. Any ideas?

Global $hTimer = TimerStart()

While 1
   If TimerStop($hTimer) >= (10000) Then Reconnect()

WEnd

Func Reconnect()
Sleep(10000)
Send("/logout")
Send("{ENTER}")
Sleep(10000);wait 10 seconds before continuing
Send("{ENTER}");
Sleep(7000);wait 7 seconds
Send("{ENTER}");
Sleep(7000);wait 7 seconds
Send("{ENTER}");
 
$hTimer = TimerStart(); Reset

EndFunc
Edited by HelloIDistance
Link to comment
Share on other sites

  • Developers

Are you sure that this is the script you are testing with and only runs once ?

It has errors in it and won't run without Autoit telling you so....:

- missing Wend

- Using buildin Function Log() as a Func name

- don't see anywhere a Timerstop() to calculate the time gone since the Timerstart()

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Instead of testing $hTimer, use TimerStop($hTimer). You don't actually care what $hTimer is (see technical note below.) If you want to test for elapsed time, like you are in your script, you need to call TimerStop, which will return the difference in time between now, and the time when you started the $hTimer.

Technical note: (if this is complicated, or makes no sense, please ignore it as it is not important) the $hTimer actually giving you the numer of milliseconds since the epoch, which is a fixed date in the past (Jan 1st, 1970 at 00:00:00.) This is a very large number, and is really only usefull to us when we compare it to another value. When used this way, we end up with a very accurate method to tell how much time has occured between 2 events.

[font="Optima"]"Standing in the rain, twisted and insane, we are holding onto nothing.Feeling every breath, holding no regrets, we're still looking out for something."[/font]Note: my projects are off-line until I can spend more time to make them compatable with syntax changes.

Link to comment
Share on other sites

Instead of testing $hTimer, use TimerStop($hTimer). You don't actually care what $hTimer is (see technical note below.) If you want to test for elapsed time, like you are in your script, you need to call TimerStop, which will return the difference in time between now, and the time when you started the $hTimer.

Technical note: (if this is complicated, or makes no sense, please ignore it as it is not important) the $hTimer actually giving you the numer of milliseconds since the epoch, which is a fixed date in the past (Jan 1st, 1970 at 00:00:00.) This is a very large number, and is really only usefull to us when we compare it to another value. When used this way, we end up with a very accurate method to tell how much time has occured between 2 events.

Thanks, Yea I can't believe I was confused over that for an hour. I was using the little script Vil told me in my pervious thread, Trying to get used to this, and I am doing little examples to help me understand.

Thanks for the quick response :D

Edited by HelloIDistance
Link to comment
Share on other sites

Another note on your code: I strongly suggest that you include a Sleep(100) function (or at least some amount of a pause, no need to go lower unless you have a special reason) so that you don't max out your CPU. If you don't incldue it, the computer will use 100% of the CPU calculating over and over if the Timer is over 10 seconds. There should never be a need to test this condition 100 times a minute, so you probably want to save your CPU from all the hard work with a sleep command.

[font="Optima"]"Standing in the rain, twisted and insane, we are holding onto nothing.Feeling every breath, holding no regrets, we're still looking out for something."[/font]Note: my projects are off-line until I can spend more time to make them compatable with syntax changes.

Link to comment
Share on other sites

Another note on your code: I strongly suggest that you include a Sleep(100) function (or at least some amount of a pause, no need to go lower unless you have a special reason) so that you don't max out your CPU. If you don't incldue it, the computer will use 100% of the CPU calculating over and over if the Timer is over 10 seconds. There should never be a need to test this condition 100 times a minute, so you probably want to save your CPU from all the hard work with a sleep command.

Yea, that wouldn't be to nice. So your talking about putting a sleep command before my WEnd? Or between the WEnd and the Func Reconnect()?

Link to comment
Share on other sites

Yea, that wouldn't be to nice. So your talking about putting a sleep command before my WEnd? Or between the WEnd and the Func Reconnect()?

In the while loop, which means before the WEnd statement. If you think like the computer for a moment and get into that loop, the only way you get out is if the timer difference is larger than 10 seconds. So it will test that condition, and then hit the WEnd command. Without the Sleep command, it will turn around right away and test the value of the timer again. To prevent this, just drop a Sleep(100) line somewhere in your While loop.

Edited to correct a small typo

Edited by pekster

[font="Optima"]"Standing in the rain, twisted and insane, we are holding onto nothing.Feeling every breath, holding no regrets, we're still looking out for something."[/font]Note: my projects are off-line until I can spend more time to make them compatable with syntax changes.

Link to comment
Share on other sites

I understand what your saying. Okay I worked on this While..WEnd stuff for awhile and I thought I had the hang of it. So I tried to implement it within the other code I had. Well it doesn't work :/. There are no errors or anything, but when I run it with the other code it never does the While...WEnd? Any ideas on why?

Here is what I have before the WEnd:

Sleep(60000);give time to open FFXI

$fisha = 2; 
$event = 0; 
$bite = 0; 
$failsafe=0; 
$nobait = 0;
WinWaitActive("FFXiApp");

While $fisha > 1 
AutoItSetOption("SendKeyDelay", 40); 
Send ("!1"); fishing macro 
$event = 0; 
$failsafe = 0; 
$nobait = 0; 

Do 
Sleep(250); 

If PixelGetColor(22,994) = 16777215 AND PixelGetColor(108,996) = 16777215 AND PixelGetColor(228,997) = 16777215 Then 
AutoItSetOption("SendKeyDelay", 40); 
Sleep(Random(3000,3200)); 
Send("{ENTER}"); 
Sleep(5400); 
EndIf 

If PixelGetColor(43,997) = 16777215 AND PixelGetColor(83,998) = 16777215 AND PixelGetColor(175,999) = 16777215 Then 
Sleep(Random(5100,5400));You lost your catch. Finish and speed things up a little. 
$event = 1; 
EndIf 

If PixelGetColor(37,1000) = 16777215 AND PixelGetColor(77,1000) = 16777215 AND PixelGetColor(180,998) = 16777215 Then 
Sleep(Random(5100,5400));You didn't catch anything. Finish and speed things up a little. 
$event = 1; 
EndIf 

If PixelGetColor(47,1000) = 16777215 AND PixelGetColor(142,999) = 16777215 AND PixelGetColor(330,997) = 16777215 Then 
$nobait = 1;You ran out of bait so let's get ready to change it. 
EndIf 

If PixelGetColor(43,995) = 16777215 AND PixelGetColor(71,997) = 16777215 AND PixelGetColor(84,995) = 16777215 Then 
autosort() 
Sleep(Random(2100,2200)); 
$event = 1;You caught something so now autosort, sleep a bit, and finish the event. 
EndIf 


$failsafe = $failsafe+1; 
If $failsafe = 175 Then 
$event = 1; 
EndIf 

Until $event = 1 

sleep(2000); 

If $nobait = 1 Then 
Send("!2");change bait 
EndIf 

WEnd
WEnd

Note: I had to put in two WEnd s for some reason. I believe becuase of the While in the loop, and there is another while, While $fisha > 1.

Link to comment
Share on other sites

There are no errors or anything, but when I run it with the other code it never does the While...WEnd? Any ideas on why?

Because it's not getting there. You'll have to debug your code to find out why, because I 1) don't own the game 2) never wish to and 3) don't want to try and hunt through your gaming script to find your intent error. Usually this is caused by it getting stuck in another loop beforehand. Try using tooltips or message boxes to debug your code by letting you know when you hit various parts of it so you can see what isn't getting run.

[font="Optima"]"Standing in the rain, twisted and insane, we are holding onto nothing.Feeling every breath, holding no regrets, we're still looking out for something."[/font]Note: my projects are off-line until I can spend more time to make them compatable with syntax changes.

Link to comment
Share on other sites

That method works great. I fixed it real quick the problme was I had the code after the timer, and then the WEnd. Here it is now:

Global $hTimer = TimerStart()

While 1
  If TimerStop($hTimer) >= (10000) Then Reconnect()

WEnd

;Code

Func Reconnect()
Sleep(10000)
Send("/logout")
Send("{ENTER}")
Sleep(10000);wait 10 seconds before continuing
Send("{ENTER}");
Sleep(7000);wait 7 seconds
Send("{ENTER}");
Sleep(7000);wait 7 seconds
Send("{ENTER}");

$hTimer = TimerStart(); Reset

EndFunc

Thanks again pek!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...