Page 1 of 1

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

Posted: Thu Jan 19, 2023 3:44 pm
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?

Re: Cycle through vJoy axis values with repeated button press

Posted: Thu Jan 19, 2023 5:21 pm
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

Re: Cycle through vJoy axis values with repeated button press

Posted: Thu Jan 19, 2023 7:09 pm
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.

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

Posted: Fri Jan 20, 2023 2:34 am
by Jabberwock
Glad to help!