Jump to content

if $x drops 20% in 10 seconds then?

Recommended Posts

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

  if $y <= $x * 0.8 and TimerDiff($timer) >= 10000 then
   ;do something
     $timer = TimerInit()
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
Link to post
Share on other sites

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
     ; Decrease the $y value or something?
Edited by Burrup


Link to post
Share on other sites

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


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]
for $i=0 to 10
$timer = TimerInit()
#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)
$btn = GUICtrlCreateButton ("Ok", 40,  75, 60, 20)
GUISetState () 

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

func checker()
    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)
        $x=ControlGetText("My GUI input acceptfile","","Edit1")
    $y1[$y]=ControlGetText("My GUI input acceptfile","","Edit1")

AutoIt3, the MACGYVER Pocket Knife for computers.

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
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...