[SOLVED] Cycle through vJoy axis values with repeated button press

Official forum for open source FreePIE discussion and development.
Post Reply
Billhelm
One Eyed Hopeful
Posts: 14
Joined: Fri Oct 11, 2013 7:01 pm

[SOLVED] Cycle through vJoy axis values with repeated button press

Post by Billhelm »

Hi all,

I'm trying to create a script to toggle between three vJoy axis values with a repeated key press. Something like this:

Code: Select all

x = 0

if x = 0 and keyboard.getPressed[A]:
	x = 512

if x = 512 and keyboard.getPressed[A]:
	x = 1024

if x = 1024 and keyboard.getPressed[A]:
	x = 0

vJoy[0].x = x
Sadly, this doesn't work because I have no idea what I'm doing.

Error: unexpected token '='

Is this a formatting error? Am I missing a step? Misunderstanding a concept? Something else?
Last edited by Billhelm on Thu Jan 19, 2023 7:15 pm, edited 2 times in total.
Jabberwock
Cross Eyed!
Posts: 197
Joined: Mon Mar 02, 2015 3:58 pm

Re: Cycle through vJoy axis values with repeated button press

Post by Jabberwock »

In Python (and several other languages) single = is used only as assignment operator. To test equality, you have to use ==. So it should be:

Code: Select all

if x == 0 and keyboard.getPressed[A]:
	x = 512
Billhelm
One Eyed Hopeful
Posts: 14
Joined: Fri Oct 11, 2013 7:01 pm

Re: Cycle through vJoy axis values with repeated button press

Post by Billhelm »

Thank you so much. I had a couple of other issues, but your suggestion got me headed in the right direction. If anyone is trying to follow in my footsteps, this is what I came up with:

Code: Select all

from System import Int16
import time
if starting:
	slider = 0
	vJoy[0].slider = slider

if vJoy[0].slider  == 0 and keyboard.getPressed(Key.A):
	vJoy[0].slider = 32767

if vJoy[0].slider  == 32767 and keyboard.getPressed(Key.A):
	vJoy[0].slider = 65535

if vJoy[0].slider  == 65535 and keyboard.getPressed(Key.A):
	vJoy[0].slider = 0
	
diagnostics.watch(vJoy[0].slider)
The slider starts at min. Pressing A on the keyboard will cycle through mid, max, min repeatedly, which is exactly what I wanted.
Jabberwock
Cross Eyed!
Posts: 197
Joined: Mon Mar 02, 2015 3:58 pm

Re: [SOLVED] Cycle through vJoy axis values with repeated button press

Post by Jabberwock »

Glad to help!
Post Reply

Return to “FreePIE”