Functions returning two different results every time

Get help with using AutoHotkey and its commands and hotkeys
Source-X
Posts: 2
Joined: 13 Mar 2017, 15:35

Functions returning two different results every time

13 Mar 2017, 16:00

Hi all,

I'm new to programming and I'm not sure why the function I created produces two different result every time, going back and forth. Here's the example code:

Code: Select all

aTime := A_Tickcount
Sleep, 1000
loop
{
	aTime := compareTime(aTime)
	MsgBox, %aTime%, %A_TickCount%
}

compareTime(givenTickCount)
{
	result := A_TickCount - givenTickCount
	return, result
}
I keep getting both, original A_Tickcount value and result value. I am trying to get the difference value between previous tickcount and current tickcount and compare it for my script, but I cannot do so properly without the function I provided giving me extra results I don't want. I don't know what went wrong.

Thanks in advance.
ManualColdLock
Posts: 175
Joined: 15 Dec 2016, 04:27

Re: Functions returning two different results every time

13 Mar 2017, 17:08

aTime := A_Tickcount

then aTime := compareTime(aTime) which is A_TickCount - givenTickCount

if you substitute real numbers....
a tick count = 1000
then atime = 1000
wait 5 then
a tick = 1005
set atime to 1005 - 1000 = 5

now atime = 5

wait 30 this time & do it again
a tick count = 135
set atime to atick - atime is 135 - 5 = 130

so you're never getting the answer you want. and it's fluctuating between extremely wrong big and extremely wrong small

Code: Select all

StartTime := A_Tickcount
sleep, 100
loop
{

	MsgBox, % TimeElapsed(A_Tickcount,StartTime)
}

TimeElapsed(a,b)
{
return a-b	
}
or without a function

Code: Select all

StartTime := A_Tickcount
sleep, 100
loop
	MsgBox, % A_Tickcount - StartTime " ms elapsed"
labedNadjib
Posts: 3
Joined: 16 Dec 2016, 18:40
Facebook: http://facebook.com/profile.php?id=100011403841640

Re: Functions returning two different results every time

13 Mar 2017, 17:51

use objects, if you dont have any idea about that, see this little youtube tuto : youtubecom/watch?v=zbXZqGfJgA0
Source-X
Posts: 2
Joined: 13 Mar 2017, 15:35

Re: Functions returning two different results every time

13 Mar 2017, 23:18

I got it figured out and I think I understand a bit better after seeing your code and the links y'all posted. Thanks guys, I appreciate it!

Return to “Ask For Help”

Who is online

Users browsing this forum: No registered users and 36 guests