joystick stubborn

Posted By: JazzDude

joystick stubborn - 08/19/12 19:09

Using this code, the mouse works but the joystick doesn't

while (mouse_left == on)||(joy_1 == on)
{
fire_bullets();
boost_anim();
wait(-0.2);
}

The joystick tests okay.
Posted By: Iglarion

Re: joystick stubborn - 08/19/12 19:26

Try this:

while(joy_1 || mouse_left == on){
beep();
wait(1);
}


Posted By: JazzDude

Re: joystick stubborn - 08/19/12 19:51

Thanks, but it still doesn't work.
Posted By: Iglarion

Re: joystick stubborn - 08/19/12 20:00

I just tested and work well, of course you need put this in while loop. You not hear the beep when you prees one of this buttons?
Posted By: JazzDude

Re: joystick stubborn - 08/19/12 20:09

It is in a while loop, and yes, it works with the mouse. The joystick pan and tilt work. But I'm not getting anything from the fire button or any other button. It's a USB joystick and it works okay on flight sims.

There's not much info in the manual or forum search to help.
Posted By: Iglarion

Re: joystick stubborn - 08/19/12 20:36

Hmm this is strange... if you say your joystick buttons works in other games and windows test, then really i do not know why wont work in 3dgs, because it should be so simple, and it is nice explained in the manual.
Posted By: Error014

Re: joystick stubborn - 08/19/12 21:14

Hey,

let's try if we can at least find what causes this.

Can you check what value

Code:
num_joysticks



has?

An easy way to do so would be to add this function to your game, then press "j" and let us know what number appears:

Code:
function numjoysticktest_startup() {
while(!key_j) wait(1);
error(str_for_num(NULL,num_joysticks));
}



This should give us a hint whether or not that joystick is getting recognized at all.


Another possible thing to check: Perhaps it's not registered as the first joystick, or it's not the first button. To check for that, consider adding this function:

Code:
function numjoysticktest_startup() {
while(!key_k) wait(1);
while(key_k) wait(1);
error("Ready!");
while(key_any) wait(1);
while(key_any==0) wait(1);
error(str_for_num(NULL,key_lastpressed));
}



If you add that function to your code, then hit [K], a prompt reading "Ready!" will appear. Click "OK", then (before hitting any other key) hit your joystick button.
It will (if it recognizes the joystick, at least) report the scancode of whichever key was pressed. You can then check the manual to see what key that is, or report to us the number and we can check that together.
Posted By: JazzDude

Re: joystick stubborn - 08/19/12 21:44

Sounds good. I'm on it.
Posted By: JazzDude

Re: joystick stubborn - 08/19/12 21:58

First test reported 1
Second 256 Joy_1

...and the mystery grows deeper.
Posted By: Error014

Re: joystick stubborn - 08/19/12 22:20

Ah, a challenge!
Well, let's check that value then!

Try adding this function to your script and let us know what numbers appear on the screen!

Code:
function alovelytestofalovelykey_startup() {
while(1) {
draw_text(str_for_num(NULL,joy_1),1,1,vector(255,255,255));
draw_text(str_for_num(NULL,key_pressed(256)),1,20,vector(255,255,255));
wait(1);
}
}



It should - in theory - display "0" and "0" if you don't press the joystick button, and "1", "1" otherwise.
Posted By: JazzDude

Re: joystick stubborn - 08/19/12 22:25

That post will get you points for the most sensitive function name.
Posted By: JazzDude

Re: joystick stubborn - 08/19/12 22:33

Works perfectly

O appears

Fire button changes it to 1

But no bullets

I changed it to mouse_left and 280 and it worked for the mouse and I also got bullets.

So it's not the joystick that's cranky. It's the bullets. LOL
Posted By: JazzDude

Re: joystick stubborn - 08/19/12 22:56

I found the problem. I added this code to allow the bofors gun to pan and tilt smoothly with the camera when firing. I don't know yet why but at least I know where.

Code:
while (mouse_left == off)
		{
		vec_set (weapon_offset.x, vector (120, 5, -35));
		vec_rotate (weapon_offset.x, vector (camera.pan, camera.tilt,0)); 
		vec_add (weapon_offset.x, camera.x);
		vec_set (my.x, weapon_offset.x);
		my.pan -= 8 * mouse_force.x * time_step;   
		my.tilt += 8 * mouse_force.y * time_step;
		my.tilt = clamp(my.tilt, -25, 85);
		wait (1);
		}
		while (joy_1 == off)
		{
		vec_set (weapon_offset.x, vector (120, 5, -35));
		vec_rotate (weapon_offset.x, vector (camera.pan, camera.tilt,0)); 
		vec_add (weapon_offset.x, camera.x);
		vec_set (my.x, weapon_offset.x);
		my.pan -= 2 * joy_force.x * time_step;   
		my.tilt += 2 * joy_force.y * time_step;
		my.tilt = clamp(my.tilt, -25, 85);
		wait (1);
		}


Posted By: JazzDude

Re: joystick stubborn - 08/19/12 23:04

Okay...thanks for all the help. All's well. I changed some "whiles" to "ifs" and that solved the problem.
© 2024 lite-C Forums