Refresh main function?
Refresh main function?
Hey
Quick question:
If I was in the middle of the main function, would there be a way to start from the beginning again, like restart it? (ie, could I use main(); or is there another way)?
Quick question:
If I was in the middle of the main function, would there be a way to start from the beginning again, like restart it? (ie, could I use main(); or is there another way)?
It's better to use a while loop, but you could use labels
e.g.
e.g.
Code: Select all
void main(void) {
start:
printf("blah/n");
// do stuff
if (...) goto start;
}
Thanks a bunch, jas0nuk!jas0nuk wrote:It's better to use a while loop, but you could use labels
e.g.
Code: Select all
void main(void) { start: printf("blah/n"); // do stuff if (...) goto start; }
Expect a release from me in a few hours! :)
Oh, and I have another question.
I'm not using callbacks (so there's no "Do you want to exit the game?" screen), and in my program I'm using:
But when I press [Home], it doesn't do anything. Is there something wrong with my code?
I'm not using callbacks (so there's no "Do you want to exit the game?" screen), and in my program I'm using:
Code: Select all
if(pad.Buttons & PSP_CTRL_HOME) {
pspDebugScreenClear();
printf("\n\n\n\n\n\n\n\n\n\n Bye, Bye! \n\n"
"- This has been a pj1115 production!");
sceKernelDelayThread(10*1000*1000);
sceKernelExitGame();
}
Your program needs to run in kernel mode when you want to catch the home button. I had the same problem recently.
Check this:
http://forums.ps2dev.org/viewtopic.php?t=7663
Check this:
http://forums.ps2dev.org/viewtopic.php?t=7663
Thanks, worked like a charm!
I'm releasing it now, it's called 'Outa-Space PSP'.
Here's the download, and I've submitted it to QJ.
http://www.sendspace.com/file/as9nxq
I'm releasing it now, it's called 'Outa-Space PSP'.
Here's the download, and I've submitted it to QJ.
http://www.sendspace.com/file/as9nxq
Using lables and goto - bad style. I prefer:
Code: Select all
for(...;...;...)
{
...
if(...) continue;
...
}
Using labels and gotos is only considered bad style if you buy into the whole "structured" programming style. If you aren't trying to be 100% structured, there's absolutely nothing bad about using labels and gotos in any manner at all.
I think they push structured programming style too much these days. It's one of the main contributors to code bloat.
I think they push structured programming style too much these days. It's one of the main contributors to code bloat.
You'll find a lot of debate about goto/labels...
In certain cases, and if you're a good programmer, you can make clean and efficient use of goto and labels; the Linux kernel for example uses them frequently for clean error handling.
But for most new programmers, it's recommended that you just steer clear of them completely, as they can quickly lead to bad habits and keep you from learning other useful code structures like do/while, switch/case, etc.
In certain cases, and if you're a good programmer, you can make clean and efficient use of goto and labels; the Linux kernel for example uses them frequently for clean error handling.
But for most new programmers, it's recommended that you just steer clear of them completely, as they can quickly lead to bad habits and keep you from learning other useful code structures like do/while, switch/case, etc.
These "problems" and "bad habits" people like to claim are more prevalent in non-structured programs are just as common in structured programs in my experience. Not closing files or freeing memory is due to a poorly constructed program, not the style of construction.dot_blank wrote:not to mention you goto somewhere; and you miss closing a file pointerf or even opening one :P ....this is most common problem
memory drip drip drip