Sign in to follow this  
Followers 0
ZebrasInBlankets

if $x drops 20% in 10 seconds then?

4 posts in this topic

#1 ·  Posted (edited)

I need to check if a variable drops more then 20% in 10 seconds, then do something. I am not sure exactly how to do this and I can't seem to dream it up either. So far this is all I have come up with.

$x = 100
$timer = TimerInit()
$y = IniRead("main.ini", "Main", "y", "NotFound")
$z = 0

do
  if $y <= $x * 0.8 and TimerDiff($timer) >= 10000 then
   ;do something
  else
     $timer = TimerInit()
   endif
until $z = 1

I don't have access to a computer with autoit at the moment to test. Would this code work and is there a better or alternate method you know of?

Edited by ZebrasInBlankets

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Made an example half based on your code. The ((20 / 100) * $x) works out 20% of the original value, not the changing one

$x = 50; Constant original value
$y = 50; The number you want to check if it changes. Same as above.

$timer = TimerInit()

while 1
   If $y <= ((20 / 100) * $x) and TimerDiff($timer) <= 10000 then
     ;do something
   Else
     ; Decrease the $y value or something?
   EndIf
Wend
Edited by Burrup

[u]Old Projects:[/u]A3MORGB2Hex[u]Old Functions:[/u]_TimeAdd/_TimeSub_AddComma_BubbleSort _RippleSort "He who does not understand your silence will probably not understand your words." - Elbert Hubbard.

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Yes it would reset the timer back to 0, but doesn't it defy the purpose? If your trying to see if in less than or equal to 10 seconds it can drop, but you just keep resetting the timer... The While...Wend loop will not take 10 seconds to complete lol and will probably do it like 15 times a second? How will the timer reach 10 seconds if you keep resetting it?

Edited by Burrup

[u]Old Projects:[/u]A3MORGB2Hex[u]Old Functions:[/u]_TimeAdd/_TimeSub_AddComma_BubbleSort _RippleSort "He who does not understand your silence will probably not understand your words." - Elbert Hubbard.

Share this post


Link to post
Share on other sites

Played around with changing iit in a gui.

Basically I have a check every second to see if the value 10 seconds ago is over the 20% thing.

I keeps going unless it finds one and then will pop up an alert box

Try changing it slowly, and then fast

dim $y,$x,$y1[11]
$x=100
for $i=0 to 10
    $y1[$i]=$x
    next
$timer = TimerInit()
AdlibEnable("checker")
#include <GUIConstants.au3>

GUICreate("My GUI input acceptfile", 320,120, @DesktopWidth/2-160, @DesktopHeight/2-45, -1, 0x00000018); WS_EX_ACCEPTFILES
$file = GUICtrlCreateInput ( "100", 10,  5, 300, 20)
GUICtrlSetState(-1,$GUI_ACCEPTFILES)
$btn = GUICtrlCreateButton ("Ok", 40,  75, 60, 20)
GUISetState () 

$msg = 0
While $msg <> $GUI_EVENT_CLOSE
       $msg = GUIGetMsg()
       Select
           Case $msg = $btn
               exitloop
       EndSelect
Wend
MsgBox (4096, "drag drop file", GUICtrlRead($file))



func checker()
    $y=int(TimerDiff($timer)/1000)
    if $y>9 then $y=$y-int($y*.1)*10
        tooltip($y & @crlf & $x & $y1[$y],0,0)
    if $y1[$y]*.8 > $x then 
        msgbox(1,"alert",$y1[$y] & @crlf & $x)
    Else
        $x=ControlGetText("My GUI input acceptfile","","Edit1")
    EndIf
    
    $y1[$y]=ControlGetText("My GUI input acceptfile","","Edit1")
EndFunc

AutoIt3, the MACGYVER Pocket Knife for computers.

Share this post


Link to post
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
Sign in to follow this  
Followers 0