Jump to content

If value goes down


Go to solution Solved by abberration,

Recommended Posts

Hey um, i don't really know how to explain this without confusing you guys so i'll give it my best shot... i hope that someone knows a solution to this; as again this is just me testing my ability with autoit.

I have a form that i made and the value goes down randomly (for the sake of testing) and when it goes down to whatever value randomly, it will shoot back up to 100% eventually and repeat the process at a random intervel. 

(I guess you could think of it like a health bar? Not sure if thats the perfect description.)

 

I have a "while" loop going on where it constantly checks that value and make sure it is 100%. 

If it is 100% it will just set a label or something to "Full"  and if it is not 100%, it will go and say "Lowered" on that label.

It will say "Lowered" until it is 100%, obviously.

but thats not what i want; i want it to say decreased for a temporary amount of time like 1 second, or 2 seconds and then just wait for the value to go down again... but i have absolutetly NO idea how i would go about doing this , and i'm dang determinded to do this somehow. 

If anyone knows how i would go about doing this please help. 

 
 
 
While 1


Detect()




Wend


Func Detect()
$read = GuiCtrlRead($Label1)


If $read = 100 Then
GuiCtrlSetData($Label2,"Full")
Else
GuiCtrlSetData($Label2,"Decreased!")
EndIf
 Endfunc

For the sake of this i didn't bother adding the includes and stuff since i know that's well.

I'm hoping someone has the intelligence to help me with this

Link to comment
Share on other sites

  • Solution

I'm giving an example using random numbers between 1-100. Hopefully, it will set you on the right track. If you have questions, feel free to ask.

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

$Form1 = GUICreate("Form1", 298, 75)
$Label1 = GUICtrlCreateLabel("Random Number:", 8, 8, 87, 17)
$Label2 = GUICtrlCreateLabel("0", 96, 8, 36, 17) ; The random number - start with zero
$Label3 = GUICtrlCreateLabel("Status:", 8, 40, 37, 17)
$Label4 = GUICtrlCreateLabel("No Change", 48, 40, 96, 17) ; The status
$Button1 = GUICtrlCreateButton("Hit Me", 192, 24, 75, 25)
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            $read = GUICtrlRead($Label2) ; read current number
            $newNum = Random(1, 100, 1) ; generate a new random number
            GUICtrlSetData($Label2, $newNum) ; set the new random number on the program
            If $newNum < $read Then
                GUICtrlSetData($Label4, "Lowered")
            ElseIf $newNum > $read Then
                GUICtrlSetData($Label4, "Increased")
            Else
                GUICtrlSetData($Label4, "No Change") ; if not lower or higher than previous, the only possibility left is the same number was generated
            EndIf
    EndSwitch
WEnd
Link to comment
Share on other sites

 

I'm giving an example using random numbers between 1-100. Hopefully, it will set you on the right track. If you have questions, feel free to ask.

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

$Form1 = GUICreate("Form1", 298, 75)
$Label1 = GUICtrlCreateLabel("Random Number:", 8, 8, 87, 17)
$Label2 = GUICtrlCreateLabel("0", 96, 8, 36, 17) ; The random number - start with zero
$Label3 = GUICtrlCreateLabel("Status:", 8, 40, 37, 17)
$Label4 = GUICtrlCreateLabel("No Change", 48, 40, 96, 17) ; The status
$Button1 = GUICtrlCreateButton("Hit Me", 192, 24, 75, 25)
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            $read = GUICtrlRead($Label2) ; read current number
            $newNum = Random(1, 100, 1) ; generate a new random number
            GUICtrlSetData($Label2, $newNum) ; set the new random number on the program
            If $newNum < $read Then
                GUICtrlSetData($Label4, "Lowered")
            ElseIf $newNum > $read Then
                GUICtrlSetData($Label4, "Increased")
            Else
                GUICtrlSetData($Label4, "No Change") ; if not lower or higher than previous, the only possibility left is the same number was generated
            EndIf
    EndSwitch
WEnd

Thanks alot for your help.

:-)

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...