|
Post by drpclind on Mar 29, 2007 10:23:18 GMT -5
Hi,
I am trying to read the button state from my joystick (WingMan RumblePad), but I keep getting an error when trying to access joystick.Button().
Here is the code that I added to the joystick.b2d example program:
40: dim i,s,b,n,y 41: y = 200 42: n = joystick.NumberOfButtons 43: for i = 0 to n-1 44: b = joystick.Button(i) 45: s = "B " & CStr(i) & ": " & CStr(b) 46: graphics.SetText s,10,y,Font1 47: y = y + 20 48: next
This is the error message:
** ERROR ** Type mismatch: 'joystick.Button' Line: 44 Column :8
The number of buttons is reported as 9, but I get the subscript error for any subscript other than 0. For example, joystick.Button(0) does not throw an error, but the value returned is always 0, no matter what button is pressed, and joystick.Button(1) gives a subscript error.
Any idea what I am doing wrong?
Thanks,
Peter
|
|
|
Post by Guilect on Mar 29, 2007 10:43:25 GMT -5
Hello Peter,
You are doing nothing wrong.
When sending a 0 to the joystick.button command the function simply returns 0. This is proper behavior, because if you have 0 buttons then how can it return a value.
Now in the case where you have 9 buttons, then sending it, e.g. 1, B2D should return the status of that button (either a 1 or a 0). What I found was that there is a small typo in the joystick.button function of B2D. When it got there I do not know. But I will correct it very soon and post the fix.
|
|
|
Post by drpclind on Mar 29, 2007 11:13:46 GMT -5
Hi, Guilect,
I'm happy to hear that the problem is related to a small typo, and not to my lack of understanding! I look forward to the fix.
Thanks for the help!
Peter
|
|
|
Post by hartnell on Mar 30, 2007 1:50:02 GMT -5
|
|
|
Post by drpclind on Mar 30, 2007 21:12:40 GMT -5
Hi,
Yes, it seems to be working properly now. Thanks for fixing it so quickly.
Here's a related issue: The following code causes an error, but I don't understand why.
dim i,n,y,s y = 200 n = joystick.NumberOfButtons for i = 1 to n s = CStr(joystick.Button(i)) graphics.SetText s,10,y,Font1 y = y + 20 next
** ERROR ** Type mismatch: 'joystick.Button' Line: 45 Column :3
It seems that it doesn't like a variable (i) used as a subscript, because if I change this to a constant (1), it runs fine...
Peter
|
|
|
Post by Guilect on Mar 31, 2007 7:43:13 GMT -5
Hi,
For now change this line:
s = CStr(joystick.Button(i))
to:
s = CStr(joystick.Button(CLng(i)))
I will make the change in B2D for the next release.
|
|