Welcome! Log In Create A New Profile

Advanced

Switch-Case inputs

Posted by SpaceJump 
Switch-Case inputs
December 12, 2008 01:27PM
I want to read an Wiimote input (a held button):
u16 buttonsHeld = WPAD_ButtonsHeld(0);

Now I know how to read what button is being held with if:
if (buttonsHeld & WPAD_BUTTON_A ) { 
        printf("Button A is being held down.\n");
}
else {
  if (buttonsHeld & WPAD_BUTTON_1){
	printf("Button 1 is being held down.\n");
  }
}

How can I read what button is held with a Switch-Cause statement?

Thanks in advance,
SJ
Re: Switch-Case inputs
December 12, 2008 01:35PM
 switch( buttonsHeld )
 {
  case WPAD_BUTTON_1:
   break;
  case WPAD_BUTTON_2:
   break;
 }

Edit: D'oh sorry, that will only work if only 1 button is down at a time...

Edit 2: You can't do a switch if there's the possibility of several outcomes. If the user presses 1 and 2, unless you add
  case WPAD_BUTTON_1 | WPAD_BUTTON_2:
   break;



Edited 2 time(s). Last edit at 12/12/2008 01:37PM by whodares.
Re: Switch-Case inputs
December 12, 2008 03:22PM
@SpaceJump:
When 2 buttons are pressed do you want them to have the same effect as if they were pressed separately?
(example: A: shoot, B: jump, A+B: shoot and jump)

Then use a lot of IFs in the right places. Check for the A button where it makes sense in your code, and check for the B button, where it makes sense.



Or do you want them to have a different effect?
(example: A: shoot, B: jump, A+B: open menu)

Then use whodare's code examples.
Re: Switch-Case inputs
December 12, 2008 04:00PM
I want to them to have a different effect (one button held at a time).

Thanks for your answers.
Re: Switch-Case inputs
December 14, 2008 09:27PM
When I call WPAD_Init(); to initialise the Wiimote, how can I make my program wait until initialising is finished?
Re: Switch-Case inputs
December 14, 2008 10:13PM
Unless your using some sort of a thread, your program SHOULD not do anything until initialization is complete.
Re: Switch-Case inputs
December 14, 2008 10:18PM
WPAD_Init() should be the first thing you do (unless you want DVD, in which case DI_Init() should happen first). Assuming you run it this early, your program shouldn't have to wait.
Re: Switch-Case inputs
December 14, 2008 10:21PM
What I think they are trying to say is that the function is blocking and will not return until the job is done.
Re: Switch-Case inputs
December 15, 2008 12:10AM
WPAD_init is the first function I call, and directly after the call I want to check if a button is held [basically I want to check if a certain button is help when the program is loaded]. But upon loading the app I see that the Wiimote flashes to late and the point of the button check is already past.



Edited 1 time(s). Last edit at 12/15/2008 12:12AM by SpaceJump.
Re: Switch-Case inputs
December 15, 2008 12:20AM
Quote
SpaceJump
[basically I want to check if a certain button is help when the program is loaded]

Why exactly do you want to do this?
Re: Switch-Case inputs
December 15, 2008 12:30AM
Because when the app loads I want it to do something when no button is being held, and something else if button A is held.
Re: Switch-Case inputs
December 15, 2008 12:55AM
WPAD_Init();

for(int pause = 0; pause < 150; pause++){

}

//Check for button press

Try this, it'll slow everything down for a tiny bit. Modify 150 if necessary.



Edited 2 time(s). Last edit at 12/15/2008 12:56AM by Arikado.
Re: Switch-Case inputs
December 15, 2008 03:55AM
Quote
Arikado
WPAD_Init();

for(int pause = 0; pause < 150; pause++){

}

//Check for button press

Try this, it'll slow everything down for a tiny bit. Modify 150 if necessary.

That won't work at all. If you want to "slow down" you can try sleep() or usleep(). But this still wouldn't help you with what you're trying to do.



Edited 1 time(s). Last edit at 12/15/2008 03:57AM by Tantric.
Re: Switch-Case inputs
December 15, 2008 07:30AM
Solving timing issue by adding a random delay is not the solution.
Re: Switch-Case inputs
December 15, 2008 08:02AM
Any other idea how I can archieve this?
Re: Switch-Case inputs
December 15, 2008 02:28PM
I have no environment to test it and I find no WPAD documentation, but
doesn't any of the functions like WPAD_GetStatus() give you the value of connected Wiimotes?

Your program could wait, until it's > 0.
Re: Switch-Case inputs
December 15, 2008 05:32PM
Quote
Tantric
That won't work at all. If you want to "slow down" you can try sleep() or usleep(). But this still wouldn't help you with what you're trying to do.
Funny, I've gotten it work in some of my past games. Usually 150 ends up being some insane number though, but it definitely works.

Better suggestion though:

while(wiimotes are not initialized){

}
Not sure what wiimotes not initialized would be I don't have libogc in front of me at the moment. There is something for it though.
Re: Switch-Case inputs
December 15, 2008 06:01PM
Quote
Arikado
Quote
Tantric
That won't work at all. If you want to "slow down" you can try sleep() or usleep(). But this still wouldn't help you with what you're trying to do.
Funny, I've gotten it work in some of my past games. Usually 150 ends up being some insane number though, but it definitely works.

My guess would be, that some compilers might optimize
for(int pause = 0; pause < 150; pause++)
to do nothing.
Re: Switch-Case inputs
December 15, 2008 08:27PM
Personnaly, I use a simple sleep() to delay after WPAD_Init before reading wiimote input

but maybe something like that might help you:

 u32 exp;
 while (WPAD_Probe(0, &exp) != WPAD_ERR_NONE);



Edited 1 time(s). Last edit at 12/15/2008 08:27PM by ekeeke.
Re: Switch-Case inputs
December 16, 2008 07:12AM
This didn't help:

for(int pause = 0; pause < 150; pause++){
}

What exactly does WPAD_GetStatus() return? When I try to printf it, I get errors.
Sorry, only registered users may post in this forum.

Click here to login