Sign in to follow this  
Followers 0
klamsi

Timeproblem in my Loop

13 posts in this topic

Hey Guys.

Have a little Problem:

I have a PIC that runs from one border of my Form to the other Site

I just made it run with this loop.

Do
   $i = $i + 3
   GUICtrlSetPos($PIC,$i,1,35,35)
   Sleep (15)

Until $i > 300

But after a while it startes to get slow. The Loop needs much more time then before.

When I move the mouse, every thing is normal again and the pic is starting to move faster again.

And after some seconds it starts to move slower again.

It seemes that the loop sleepes 200ms instead of 15ms, maybe to give the CPU time to do other Threads.

Is somebody here who knows how I can prevent this characteristic???

Greetz to all,

Klamsi

Share this post


Link to post
Share on other sites



Intention?

A little game like "snake" or "pacman"

I have a pic, and this pic should move around.

Well every thing works, but as I told, it works to slow!

After around a few loops it startes to slow down.

It seemes, that the priority of the loop gets lower then it should be.

Share this post


Link to post
Share on other sites

With such a small loop number, do you need the Sleep(15)? Does it serve some higher purpose other than trying to save cpu usage?


[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

With such a small loop number, do you need the Sleep(15)? Does it serve some higher purpose other than trying to save cpu usage?

That doesn't metter. I choosed Sleep(15) to make the movement of the PIC smoothly.

But what I mean is:

Whenever the Loop needs less then ca. 200ms to run through, the loop will slow down strongly after ca. 50 loop-passes

Why?

I just dont want that.

How can I prevent this?

Share this post


Link to post
Share on other sites

Try a For loop instead.

For $i = 1 To 300 Step 3
    GUICtrlSetPos($PIC,$i,1,35,35)
    Sleep(15)
Next

Share this post


Link to post
Share on other sites

Try a For loop instead.

For $i = 1 To 300 Step 3
    GUICtrlSetPos($PIC,$i,1,35,35)
    Sleep(15)
Next

To bad :lmao:

That was a good Idea, but it still getz so slow like before ;)

Share this post


Link to post
Share on other sites

Have you tried it with just ControlMove() to see what happens?

ControlMove($GUINAME, '', $PIC, $i, 1, 35, 35)?


[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

Have you tried it with just ControlMove() to see what happens?

ControlMove($GUINAME, '', $PIC, $i, 1, 35, 35)?

Hmmm, that chances nothing =(

Do you have an other idea?

Share this post


Link to post
Share on other sites

Hmmm, that chances nothing =(

Do you have an other idea?

Get a faster computer? :lmao: j/k

What size file is that $PIC out of curiousity...


[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

Could be a case of too much happening in such a short period of time for the PC to manage it.

Try less moves in the same time period like below.

For $i = 1 To 150 Step 6
    GUICtrlSetPos($PIC,$i,1,35,35)
    Sleep(30)
Next

That should help to release some load on the PC.

Share this post


Link to post
Share on other sites

Could be a case of too much happening in such a short period of time for the PC to manage it.

Try less moves in the same time period like below.

For $i = 1 To 150 Step 6
    GUICtrlSetPos($PIC,$i,1,35,35)
    Sleep(30)
Next

That should help to release some load on the PC.

No thats not the Problem =)

I got it with a simple trick:

Mousemove(1,1)!!!

As I explained, when I move the mouse... my problem stops.

So, thats all what I have to do... let the computer move the mouse after the 50th loop...

Its creazy... but it works :lmao:

Greetz,

Klamsi

Share this post


Link to post
Share on other sites

Almost makes you wonder if something like this would work:

Local $TestIt = ''
While $TestIt <= 10
    $MovePic = TestPicMove()
    $TestIt = $TestIt + $MovePic
WEnd

Func TestPicMove()
    For $i = 1 To 30 Step 3
        GUICtrlSetPos($PIC,$i,1,35,35)
        Sleep(15)
    Next
    Return 1
EndFunc


[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

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