simple button question..

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

Moderators: cheriff, TyRaNiD

Post Reply
shadow_91
Posts: 4
Joined: Fri Jul 15, 2005 10:13 am

simple button question..

Post by shadow_91 »

i recently started developing for the psp and was fooling around with code trying to get the buttons to work. but this code does not seem to work and im not sure what the problem with it is.

Code: Select all

int main(void)
              {
              	SceCtrlData pad;
                int status = 0;
	pspDebugScreenInit()
                SetupCallbacks();
             	sceCtrlSetSamplingCycle(0);
              	sceCtrlSetSamplingMode(PSP_CTRL_MODE_ANALOG);
                sceCtrlReadBufferPositive(&pad, 1);
                pspDebugScreenSetXY(18, 2);
                printf("control test program");   
                pspDebugScreenSetXY(2, 5);
                printf("Try Hitting X");
                                if (pad.Buttons & PSP_CTRL_CROSS){
                                        printf("X");
					status ++; 
				if (status == 1){
					printf("You have successfully completed the program. Press Home to exit"); }
					status ++;
				if (status == 2)
					sceKernelSleepThread(); }             
                            
                       return 0; }    
it gets to "Try Hitting X" and then it freezes. i'm not sure if it's something with the sleepthread, help a noob psp dev out here =).
remleduff
Posts: 11
Joined: Sun Jul 24, 2005 3:29 am

Post by remleduff »

Think about what you're trying to do, read your code and ask yourself, "Is this doing at all what I'm meaning to?"

What you have written here:
Reads the keypad once
Prints out "Try Hitting X"
Hits an if statement that will probably never be true because the user didn't realize he was supposed to press the button BEFORE the text shows up
And hits the end of main


You almost certainly want that if statement to be a while loop and you need to read the keypad within the loop.
Arwin
Posts: 426
Joined: Tue Jul 12, 2005 7:00 pm

Post by Arwin »

yeah, you're missing a loop there ...
shadow_91
Posts: 4
Joined: Fri Jul 15, 2005 10:13 am

Post by shadow_91 »

thanks, i knew i forgot something.. lemme get on that now. also, how would i get the "X" to print more than once, but on a different line? right now i have this:

Code: Select all

int main()
              {
              	SceCtrlData pad;
		int scrnset = 5;
		int count = 1;
		pspDebugScreenInit();
                SetupCallbacks();
             	sceCtrlSetSamplingCycle(0);
              	sceCtrlSetSamplingMode(PSP_CTRL_MODE_ANALOG);
		while(count >= 1){
			sceCtrlReadBufferPositive(&pad, 1);
                	scrn(18, 2);
                	printf("control test program");   
                	scrn(2, 5);
                	printf("Try Hitting X");
			if (pad.Buttons & PSP_CTRL_CROSS){
				scrn(2,scrnset +2);
				printf("X"); }	  }		 	              
                       return  0; }
note that i have defined scrn as pspdebugscreensetXY. the psp doesnt seem to want to read the (count >= 1) part, and doesnt print out anything. while(1) works, but that is not the condition i want, and only prints X out once. sorry im a little rusty on my C.
framerate
Posts: 20
Joined: Sun Aug 14, 2005 2:30 am

Post by framerate »

What is the scrn() command? I haven't seen that yet.

Also, as to your question, I learned from reading the docs, asking questions like this, and most importantly, reading other people's code.

I've been uploading my code as I work, so if you want to check it out:

www.framerate.info/psp/test.zip - simple text on screen with button input

www.framerate.info/psp/rpg_test.zip - updates this week, beginnings of the actually game code.. with image display etc

Hope that helps!
Post Reply