View Full Version: need help coding

CheatSync.net Forums > Developement > need help coding



Title: need help coding
Description: coding


w00tguy123 - November 25, 2006 11:02 PM (GMT)
I just started creating homebrew yesterday. I'm taking small steps and i have read the lessons on psp-programming.com but I am having trouble making this real simple homebrew. I want to make the program start out displaying "Press (X) for next message" and when i press x, i want it to say "this is the next message".

But when i start it up, it displays "Press (X) for the next messagethis is the next message" and sits there. Can someone please help?

Here is my code:

#include <pspkernel.h>
#include <pspdebug.h>
#include <pspdisplay.h>
#include <pspctrl.h>

PSP_MODULE_INFO("Hello World", 0, 1, 1);

#define printf pspDebugScreenPrintf

/* Exit callback */
int exit_callback(int arg1, int arg2, void *common) {
sceKernelExitGame();
return 0;
}

/* Callback thread */
int CallbackThread(SceSize args, void *argp) {
int cbid;

cbid = sceKernelCreateCallback("Exit Callback", exit_callback, NULL);
sceKernelRegisterExitCallback(cbid);

sceKernelSleepThreadCB();

return 0;
}

/* Sets up the callback thread and returns its thread id */
int SetupCallbacks(void) {
int thid = 0;

thid = sceKernelCreateThread("update_thread", CallbackThread, 0x11, 0xFA0, 0, 0);
if(thid >= 0) {
sceKernelStartThread(thid, 0, 0);
}

return thid;
}


int main() {

pspDebugScreenInit();
SetupCallbacks();
SceCtrlData pad;

while(1) { printf("Press (x) for next message");

sceCtrlReadBufferPositive(&pad, 1);
if(pad.Buttons & PSP_CTRL_CROSS) {
break;


}

printf ("this is the next message");

sceKernelSleepThread();
return 0;}

}

Li'l Freak - November 25, 2006 11:07 PM (GMT)
i think you take out the pad in pad.buttons


but i am not sure i am very very new to coding. well not very very mabe jsut kinda new.

Waterbottle - November 26, 2006 02:02 AM (GMT)
@lilfrk, don't answer if you have no idea what you are talking about.

you're problem is with wrongly set }'s

look at your code.
CODE

while(1)
{
printf("Press (x) for next message");

sceCtrlReadBufferPositive(&pad, 1);
if(pad.Buttons & PSP_CTRL_CROSS)
{
break;
}

printf ("this is the next message");

sceKernelSleepThread();
return 0;
}//end of while(1)


it tells it,

while 1, if you press X then break out of the loop, and then continiue from the } for while(1). and after checking that, if it does not break out of the loop it will then run the code
sceKernelSleepThread();
return 0;
which means it freezes the game the first time through the scrip, every time.

to get it to work you need to move the end of while(1) to right after the end of the if state ment

CODE

while(1)
{
printf("Press (x) for next message");

sceCtrlReadBufferPositive(&pad, 1);
if(pad.Buttons & PSP_CTRL_CROSS)
{
break;
}
}

printf ("this is the next message");

sceKernelSleepThread();
return 0;


or if you want a bit cleaner code (atleast IMO) you could do this,

CODE

while(!(pad.Buttons & PSP_CTRL_CROSS))
{
printf("Press (x) for next message");
sceCtrlReadBufferPositive(&pad, 1);
}

printf ("this is the next message");

sceKernelSleepThread();
return 0;

Tommy - November 26, 2006 03:39 AM (GMT)
Well why your looking at this waterbottle do you know how to port 1.5 homebrew to run on 2.8 eloader, or make 2.8 homebrew ?

w00tguy123 - November 26, 2006 05:01 AM (GMT)
oh ok, thanks water

Waterbottle - November 26, 2006 12:39 PM (GMT)
QUOTE (Tommy @ Nov 26 2006, 03:39 AM)
Well why your looking at this waterbottle do you know how to port 1.5 homebrew to run on 2.8 eloader, or make 2.8 homebrew ?

I thought the eloader supported normal 1.5 homebrew?

Tommy - November 26, 2006 03:51 PM (GMT)
Some of them, but theres alot that don't work and I'm not going to start to code and if I can't see the outcome of it. So what I was really wondering is why some didn't and why some did.
Any help would be nice.




Hosted for free by InvisionFree