 |
forums.ps2dev.org Homebrew PS2, PSP & PS3 Development Discussions
|
| View previous topic :: View next topic |
| Author |
Message |
shadow_91
Joined: 15 Jul 2005 Posts: 4
|
Posted: Fri Aug 12, 2005 1:54 am Post subject: simple button question.. |
|
|
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: |
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 =). |
|
| Back to top |
|
 |
remleduff
Joined: 24 Jul 2005 Posts: 11
|
Posted: Fri Aug 12, 2005 3:21 am Post subject: |
|
|
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. |
|
| Back to top |
|
 |
Arwin
Joined: 12 Jul 2005 Posts: 426
|
Posted: Fri Aug 12, 2005 5:54 am Post subject: |
|
|
| yeah, you're missing a loop there ... |
|
| Back to top |
|
 |
shadow_91
Joined: 15 Jul 2005 Posts: 4
|
Posted: Fri Aug 12, 2005 9:26 am Post subject: |
|
|
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: | 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. |
|
| Back to top |
|
 |
framerate
Joined: 14 Aug 2005 Posts: 20
|
Posted: Sun Aug 14, 2005 2:32 am Post subject: |
|
|
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! |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|