Oddities using sceCtrlReadBufferPositive

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
Shatterdome
Posts: 11
Joined: Tue Nov 22, 2005 6:49 pm

Oddities using sceCtrlReadBufferPositive

Post by Shatterdome »

Hello all, i'm relatively new to programing with the psp, although I am experienced in c and c++. Anyways, I'm just curious if anyone has encountered any stranges results when using sceCtrlReadBufferPositive() ?? Mainly the reason I've asked if i'm using this snippet of code...

Code: Select all

SceCtrlData pad;
sceCtrlSetSamplingCycle(0);
sceCtrlSetSamplingMode(PSP_CTRL_MODE_ANALOG);


sceCtrlReadBufferPositive(&pad, 1); 
                  

                  if (pad.Buttons & PSP_CTRL_DOWN)
                     { 
                     ymod = 1;
                      }                          

                  if (pad.Buttons & PSP_CTRL_RIGHT)
                     {
                      xmod = 1;
                     }

                               
                  if (pad.Buttons & PSP_CTRL_UP)
                    {   
                    ymod = -1;
                    }   
                     
                  if (pad.Buttons & PSP_CTRL_LEFT)
                     {
                      xmod = -1;
                     }

                                  

                     else
                    {
                      ymod = 0;
                      xmod = 0;                    
                     }

(I was only using brackets around all the if statements for debugging)

My problem is it will only respond to PSP_CTRL_LEFT and will respond to PSP_CTRL_UP/DOWN but only when i'm holding LEFT (ie diagonal up and diagonal down, to the left)

So whatever if statment I want to run I just change to LEFT and it will do it, and will do UP and DOWN only when im pressing it with LEFT (i'm assuming it'd do right if it COULD be pressed at the same time as left :P )

It's funky....and this is really frustrating me as it's a pretty simple procedure and according to the 15 different source files i've referenced that also use this statement, well it SHOULD all work fine :(

Any suggestions ?

Thanks in advance...

edit: Seems whichever statement I put at the bottom of the list, before else, works....but only for directions, as I can assign sceKernelExitGame(); to SQUARE with an if statement at the begining or middle or even last and it works every time...same with any other button...strange...
User avatar
Jim
Posts: 476
Joined: Sat Jul 02, 2005 10:06 pm
Location: Sydney
Contact:

Post by Jim »

This is really basic stuff

Code: Select all

                      ymod = 0; 
                      xmod = 0;                    

                     if (pad.Buttons & PSP_CTRL_DOWN) 
                     { 
                     ymod = 1; 
                      }                          

                  if (pad.Buttons & PSP_CTRL_RIGHT) 
                     { 
                      xmod = 1; 
                     } 

                                
                  if (pad.Buttons & PSP_CTRL_UP) 
                    {    
                    ymod = -1; 
                    }    
                      
                  if (pad.Buttons & PSP_CTRL_LEFT) 
                     {
                      xmod = -1; 
                     } 

         
In your example, the else only belongs to the last if, so unless the last if test is true, xmod and ymod are both set to 0.
Are you sure you copied the examples right? They didn't have 'else if' and not just 'if'?

Jim
Shatterdome
Posts: 11
Joined: Tue Nov 22, 2005 6:49 pm

Post by Shatterdome »

durrrll....Thanks, that did it...can't beleive I didn't realise that...I think I must have moved and checked everything except those two variables...makes sence though, why change them to 0 if yadda yadda aren't true, just have them start at 0 and have things change them as they happen....the if structure was my own creating, hence the error :P hehe, anyways thank you again very muchly...
Post Reply