ericnail Posted December 14, 2010 Share Posted December 14, 2010 Okay, So I am having an issue. I have a While loop that checks for network spikes and if it finds any, it sends the network ID to a function. In the second function I have a TimerInit() and then in the While loop I check to make sure it has been at least a second since the last spike was recorded via TimerDiff() on the started timer. My issue is that AutoIt seems to be continuing the While Loop while the Record() function is running which results in multiple sends to the Record() function before the timer is started and therefore fails to limit the amount of records made within a second. Here is the bare version of my script: Global $Net1, $Net2, $Net3, $Net4 Global $LastRecord = 1000 While 1 While $on GetNetworksData($Net1, $Net2, $Net3, $Net4) For $i = 1 to 4 $temp = Eval("Net"&$i) If $temp >= $NetworkSpikeAmount Then If TimerDiff($LastRecord) >= 1000 Then Record($LastRecord, $temp) EndIf Next WEnd WEnd Func Record(ByRef $LastRecord, $data) $fileHandle = FileOpen($File) FileWrite($fileHandle, $data & @CRLF) FileClose($fileHandle) $LastRecord = TimerInit() Return EndFunc I'm wondering how I can stop the multiple attempts and how autoit works with functions (whether it stops until the function returns or what). Thanks! Link to comment Share on other sites More sharing options...
JoHanatCent Posted December 14, 2010 Share Posted December 14, 2010 (edited) Global $LastRecord = 1000 You might want to reset $LastRecord somewere within one of your loops? The function appear to do as expected! Global $Net1, $Net2, $Net3, $Net4 Global $LastRecord = 1000 While 1 While $on GetNetworksData($Net1, $Net2, $Net3, $Net4) For $i = 1 to 4 $temp = Eval("Net"&$i) If $temp >= $NetworkSpikeAmount Then If TimerDiff($LastRecord) >= 1000 Then Record($LastRecord, $temp) EndIf Next WEnd WEnd Func Record(ByRef $LastRecord, $data) $fileHandle = FileOpen($File) FileWrite($fileHandle, $data & @CRLF) FileClose($fileHandle) $LastRecord = TimerInit() Return EndFunc Typo's Edited December 14, 2010 by JoHanatCent Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now