Jump to content

Problem with infinite loop


nwbyy
 Share

Recommended Posts

Hi

Sorry if threads like this already exist, but I don't get it to work, even with examples.

I set a bmp picture button changing on mouse hover.
Next to it, there is a jpg picture that also changes when the mouse goes over this same button.

So far no problem.

But the idea is to make the jpg picture change 3 times in a infinite loop.
Let's say a "animated gif effect".

#include <GUIConstantsEx.au3>
#include <GUICtrlSetOnHover_UDF.au3>


Global $sImages_Path    = @ScriptDir & "\Example Images"


GUICreate("OnClick Hovering Example", 580, 500)


$button = GUICtrlCreatePic($sImages_Path & "\Button.bmp", 70, 100, 40, 40)
_GUICtrl_SetOnHover(-1, "_Hover_Proc", "_Leave_Hover_Proc")


$picture = GUICtrlCreatePic($sImages_Path & "\picture 1.jpg", 300, 300, 165, 124)


GUISetState()


While 1
    $nMsg = GUIGetMsg()

    Switch $nMsg

        Case $GUI_EVENT_CLOSE
            Exit

        Case $button
            ; Any actions

         EndSwitch


WEnd


Func anim()

   While 1
      GUICtrlSetImage($picture, $sImages_Path & "\picture 2.jpg")
      Sleep(250)
      GUICtrlSetImage($picture, $sImages_Path & "\picture 3.jpg")
      Sleep(250)
      GUICtrlSetImage($picture, $sImages_Path & "\picture 4.jpg")
      Sleep(250)
   WEnd

EndFunc


Func _Hover_Proc($iCtrlID)

    Switch $iCtrlID

        Case $button
            GUICtrlSetImage($iCtrlID, $sImages_Path & "\Button_Hover.bmp")
            anim()

         EndSwitch

EndFunc


Func _Leave_Hover_Proc($iCtrlID)

    Switch $iCtrlID

        Case $button
            GUICtrlSetImage($iCtrlID, $sImages_Path & "\Button.bmp")

         EndSwitch

EndFunc

When I put the mouse over the button, the loop goes around a few times and the script crashes.
With Sleep() set on 150, the loop goes around about 10 times before crash.
Set on 250 it crashes after about 7 times. So it seems not to depend on the number of times the loop restarts.

What am I doing wrong?

Another thing I can't figure out, is how to exit the loop in the _Leave_Hover_Proc function...?

Thanks a lot.

Link to comment
Share on other sites

By adding ExitLoop() it won't be an infinite loop any more.

So I tried with conditions:

#include <GUIConstantsEx.au3>
#include <GUICtrlSetOnHover_UDF.au3>


Global $sImages_Path    = @ScriptDir & "\Example Images"


GUICreate("OnClick Hovering Example", 580, 500)


$button = GUICtrlCreatePic($sImages_Path & "\Button.bmp", 70, 100, 40, 40)
_GUICtrl_SetOnHover(-1, "_Hover_Proc", "_Leave_Hover_Proc")


$picture = GUICtrlCreatePic($sImages_Path & "\picture 1.jpg", 300, 300, 165, 124)


GUISetState()


While 1
    $nMsg = GUIGetMsg()

    Switch $nMsg

        Case $GUI_EVENT_CLOSE
            Exit

        Case $button
            ; Any actions

         EndSwitch


WEnd


Func anim()

   $exit = False

   While 1
      If $exit = False Then
         GUICtrlSetImage($picture, $sImages_Path & "\picture 2.jpg")
         Sleep(250)
         GUICtrlSetImage($picture, $sImages_Path & "\picture 3.jpg")
         Sleep(250)
         GUICtrlSetImage($picture, $sImages_Path & "\picture 4.jpg")
         Sleep(250)
      Else
         ExitLoop
      EndIf
   WEnd

EndFunc


Func _Hover_Proc($iCtrlID)

    Switch $iCtrlID

        Case $button
            GUICtrlSetImage($iCtrlID, $sImages_Path & "\Button_Hover.bmp")
            anim()

         EndSwitch

EndFunc


Func _Leave_Hover_Proc($iCtrlID)

    Switch $iCtrlID

        Case $button
            GUICtrlSetImage($iCtrlID, $sImages_Path & "\Button.bmp")
            $exit = True

         EndSwitch

EndFunc

Like this, the loop is not stoped when the mouse leaves the button, and the loop crashes the same way than before anyway.

I thaught maybe it's not possible to change the value of the $exit variable when it was set inside a function.

So I tried to set $exit = False outside the function, but then, the loop goes around only one time. Weird...

Link to comment
Share on other sites

5 minutes ago, Jos said:

Define: crashes.

When I put mouse over the button, the loop begins, goes on for about 7 times, and then comes a "autoit v3 script not responding"  window with the 3 choices:

- get online help.

- close program.

- wait for program to answer.

Link to comment
Share on other sites

  • Developers

Where did you get the GUICtrlSetOnHover_UDF.au3 from as this isn't a standard udf library?

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Thanks both for your answers by tha way.

Frome here:

True.
I remember that the download link of the lastest version is dead. So I took the one before...

Will have a look for an updated version of the file.

Edited by nwbyy
Link to comment
Share on other sites

The creator posted this about the last version of the UDF:

Quote

The disadvantage is obvious, any blocking function or loop will "freeze" the hovering events.

Which certainly explains the problem I have.

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