| View previous topic :: View next topic |
| Author |
Message |
pj1115
Joined: 22 Jan 2007 Posts: 23
|
Posted: Tue Feb 20, 2007 4:09 am Post subject: 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)? |
|
| Back to top |
|
 |
jas0nuk
Joined: 27 Apr 2006 Posts: 137
|
Posted: Tue Feb 20, 2007 4:47 am Post subject: |
|
|
It's better to use a while loop, but you could use labels
e.g.
| Code: | void main(void) {
start:
printf("blah/n");
// do stuff
if (...) goto start;
} |
|
|
| Back to top |
|
 |
pj1115
Joined: 22 Jan 2007 Posts: 23
|
Posted: Tue Feb 20, 2007 5:25 am Post subject: |
|
|
| jas0nuk wrote: | It's better to use a while loop, but you could use labels
e.g.
| Code: | void main(void) {
start:
printf("blah/n");
// do stuff
if (...) goto start;
} |
|
Thanks a bunch, jas0nuk!
Expect a release from me in a few hours! :) |
|
| Back to top |
|
 |
pj1115
Joined: 22 Jan 2007 Posts: 23
|
Posted: Tue Feb 20, 2007 5:32 am Post subject: |
|
|
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:
| Code: | 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();
} |
But when I press [Home], it doesn't do anything. Is there something wrong with my code? |
|
| Back to top |
|
 |
pailes

Joined: 16 Feb 2007 Posts: 16
|
|
| Back to top |
|
 |
pj1115
Joined: 22 Jan 2007 Posts: 23
|
Posted: Tue Feb 20, 2007 7:47 am Post subject: |
|
|
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 |
|
| Back to top |
|
 |
Cy-4AH
Joined: 31 Jan 2007 Posts: 44 Location: Belarus
|
Posted: Tue Feb 20, 2007 6:49 pm Post subject: |
|
|
Using lables and goto - bad style. I prefer:
| Code: |
for(...;...;...)
{
...
if(...) continue;
...
}
|
|
|
| Back to top |
|
 |
J.F.
Joined: 22 Feb 2004 Posts: 2906
|
Posted: Wed Feb 21, 2007 9:22 am Post subject: |
|
|
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. |
|
| Back to top |
|
 |
jimparis
Joined: 10 Jun 2005 Posts: 1179 Location: Boston
|
Posted: Wed Feb 21, 2007 6:23 pm Post subject: |
|
|
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. |
|
| Back to top |
|
 |
dot_blank

Joined: 28 Sep 2005 Posts: 498 Location: Brasil
|
Posted: Wed Feb 21, 2007 6:33 pm Post subject: |
|
|
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 _________________ 10011011 00101010 11010111 10001001 10111010 |
|
| Back to top |
|
 |
J.F.
Joined: 22 Feb 2004 Posts: 2906
|
Posted: Wed Feb 21, 2007 6:50 pm Post subject: |
|
|
| 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 |
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. |
|
| Back to top |
|
 |
|