Issue with while loops and freepie ?

Official forum for open source FreePIE discussion and development.
Post Reply
nalfein
One Eyed Hopeful
Posts: 5
Joined: Tue Sep 06, 2016 6:27 pm

Issue with while loops and freepie ?

Post by nalfein »

Hi everyone :) I'm currently trying to get a while loop to work correctly in freepie in order to calibrate one of my controller with that little example script :

Code: Select all


global calibrating

def whileLoopTest():
    global calibrating
    while (calibrating):
         diagnostics.watch("looping")
         if mouse.leftButton:
             calibrating = False             
    diagnostics.watch("done")



if starting:
    calibrating = False
    whileLoopTest()

The problem is that freepie doesn't seem to be able to get out of that loop no matter the keypress or mouse button I put as the condition. Does anyone knows where is my error or thats simply a freepie bug ?

Thanks a lot !
User avatar
zelmon64
Cross Eyed!
Posts: 134
Joined: Thu Apr 09, 2015 4:27 am

Re: Issue with while loops and freepie ?

Post by zelmon64 »

Hi. If you place diagnostics.watch(mouse.leftButton) in the while loop you can see that it doesn't get updated. The following behaves like a while loop:

Code: Select all

global calibrating

if starting:
    calibrating = True
    
if calibrating:
         diagnostics.watch("looping")
         if mouse.leftButton:
             calibrating = False            
else:        
    diagnostics.watch("done")     
nalfein
One Eyed Hopeful
Posts: 5
Joined: Tue Sep 06, 2016 6:27 pm

Re: Issue with while loops and freepie ?

Post by nalfein »

Thanks for the answer zelmon ! It looks like the code is working as I wanted :) I have a last question for you if you don't mind : Once I did the calibration code, I would like to move precisely move my mouse according to the calibration. However if I use this code:

Code: Select all

if keyboard.getPressed(Key.L):
    mouse.deltaX = -(80)
The mouse movement isn't the same than if I press "L" 8 times

Code: Select all

if keyboard.getPressed(Key.L):
    mouse.deltaX = -(10)
Is there a way to also fix that problem ?

Thanks !
User avatar
zelmon64
Cross Eyed!
Posts: 134
Joined: Thu Apr 09, 2015 4:27 am

Re: Issue with while loops and freepie ?

Post by zelmon64 »

Are you certain you get different results? I just ran a script only containing the following and as best as I can tell, pressing L eight times moved the mouse the same amount as pressing K once. I'm guessing there's something else in your script effecting it.

Code: Select all

if keyboard.getPressed(Key.K):
    mouse.deltaX = -(80)
    
if keyboard.getPressed(Key.L):
    mouse.deltaX = -(10)
nalfein
One Eyed Hopeful
Posts: 5
Joined: Tue Sep 06, 2016 6:27 pm

Re: Issue with while loops and freepie ?

Post by nalfein »

Well I still have the same issue with (almost) the same exact code. I made a video (https://www.youtube.com/watch?v=7J1bXQa ... e=youtu.be) so you can see that the mouse is definitely off his original position. I will try on my desktop once I get home but I'm pretty sure the same problem will occur. My guess (if the problem isn't my setup) is that keyboard.getPressed(Key.L) last more than one iteration of the code (because freepie refresh rate must be pretty high) and thus the mouse will move more that it suppose to.

Any though ?
User avatar
zelmon64
Cross Eyed!
Posts: 134
Joined: Thu Apr 09, 2015 4:27 am

Re: Issue with while loops and freepie ?

Post by zelmon64 »

I tried it your way with the following script but had no discrepancy between the two as can be seen in the video below. Is it possible you have another program running that interferes with the mouse like to smooth its motion? I know logitech do something like that for the scroll wheel. keyboard.getPressed should only fire once per key press as that is it's purpose.

Code: Select all

if keyboard.getPressed(Key.K):
    mouse.deltaX = -(80)
    
if keyboard.getPressed(Key.L):
    mouse.deltaX = (10)
[youtube-hd]https://www.youtube.com/watch?v=q-1gbuH ... e=youtu.be[/youtube-hd]
nalfein
One Eyed Hopeful
Posts: 5
Joined: Tue Sep 06, 2016 6:27 pm

Re: Issue with while loops and freepie ?

Post by nalfein »

Damn, even on my desktop I have the same result ... Well, I will perform a fresh install and use it with my old ps2 mouse to try it again to be sure. Will update when I get home again. Thanks for your help Zelmon!
User avatar
zelmon64
Cross Eyed!
Posts: 134
Joined: Thu Apr 09, 2015 4:27 am

Re: Issue with while loops and freepie ?

Post by zelmon64 »

nalfein wrote:Damn, even on my desktop I have the same result ... Well, I will perform a fresh install and use it with my old ps2 mouse to try it again to be sure. Will update when I get home again. Thanks for your help Zelmon!
Unfortunately I doubt having a different mouse plugged in would effect it.

I had a thought about using a for loop instead. This works for me:

Code: Select all

if keyboard.getPressed(Key.L):
    mouse.deltaX = (10)
    
if keyboard.getPressed(Key.K):
    for i in range(8):
        mouse.deltaX = -(10)
[On a side note, any idea why my vid would have been flagged as violating youtube's guidelines? After appealing they put it back up but I can't figure out why they thought it might be violating something in the first place. Thanks]
FrenchyKiel
One Eyed Hopeful
Posts: 47
Joined: Thu Oct 03, 2013 7:10 am

Re: Issue with while loops and freepie ?

Post by FrenchyKiel »

hi fyi i have read that on Microsoft site

"Relative mouse motion is subject to the effects of the mouse speed and the two-mouse threshold values. A user sets these three values with the Pointer Speed slider of the Control Panel's Mouse Properties sheet. You can obtain and set these values using the SystemParametersInfo function.

The system applies two tests to the specified relative mouse movement. If the specified distance along either the x or y axis is greater than the first mouse threshold value, and the mouse speed is not zero, the system doubles the distance. If the specified distance along either the x or y axis is greater than the second mouse threshold value, and the mouse speed is equal to two, the system doubles the distance that resulted from applying the first threshold test. It is thus possible for the system to multiply specified relative mouse movement along the x or y axis by up to four times."
nalfein
One Eyed Hopeful
Posts: 5
Joined: Tue Sep 06, 2016 6:27 pm

Re: Issue with while loops and freepie ?

Post by nalfein »

FOUND IT ! Thanks @FrenchyKiel for the hint :) In mouse properties, pointer options, there is an option called : "Enhance pointer precision" . Once I disabled that s**t, it started to work as it was in @Zelmon64 video. Should we put this in the freepie wiki ? It could (perhap) help others users who are trying to debug their script.

edit : Damn after a while, the issue started to occur again.. Will look into what @FrenchyKiel posted. Thanks for the for loop idea zelmon but I still have the same problem.
Post Reply

Return to “FreePIE”