 |
forums.ps2dev.org Homebrew PS2, PSP & PS3 Development Discussions
|
| View previous topic :: View next topic |
| Author |
Message |
Mortimus
Joined: 06 Jan 2006 Posts: 7
|
Posted: Fri Jan 06, 2006 3:37 pm Post subject: Weird bug |
|
|
When I run this code, the 2nd do while loop, wont show the month from the first do while, instead it just has it act exactly the same as the day variable, and change with each button press with the day. my print function prints the string at x, y using the font image i have.
| Code: |
do{
ClearScreen(0x000000);
print("What is your Birthday?", 20, 40);
sceCtrlReadBufferPositive(&pad, 1);
if(i<10){
month[0] = 32;
month[1] = i+48;
}else{
month[0] = 49;
month[1] = i+38;
}
//month = char(i+49);
if (pad.Buttons & PSP_CTRL_DOWN){
if(i<12){
i++;
}
}
if (pad.Buttons & PSP_CTRL_UP){
if(i>1){
i--;
}
}
while((pad.Buttons & PSP_CTRL_DOWN) || (pad.Buttons & PSP_CTRL_UP)){
sceCtrlReadBufferPositive(&pad, 1);
}
print(month, 20, 60);
SwapBuffers();
}while(!(pad.Buttons & PSP_CTRL_CIRCLE));
while(pad.Buttons & PSP_CTRL_CIRCLE){
sceCtrlReadBufferPositive(&pad, 1);
} // make sure button is depressed
do{
ClearScreen(0x000000);
print("What is your Birthday?", 20, 40);
print(month, 20, 60);
sceCtrlReadBufferPositive(&pad, 1);
if(q<10){
day[0] = 32;
day[1] = q+48;
}else{
day[0] = 48+(q/10);
day[1] = (q%10)+48;
}
if (pad.Buttons & PSP_CTRL_DOWN){
if(q<31){
q++;
}
}
if (pad.Buttons & PSP_CTRL_UP){
if(q>1){
q--;
}
}
while((pad.Buttons & PSP_CTRL_DOWN) || (pad.Buttons & PSP_CTRL_UP)){
sceCtrlReadBufferPositive(&pad, 1);
}
print(day, 70, 60);
SwapBuffers();
}while(!(pad.Buttons & PSP_CTRL_CIRCLE));
|
_________________ ~ Mortimus ~ |
|
| Back to top |
|
 |
Nige

Joined: 29 Sep 2005 Posts: 10
|
Posted: Sat Jan 07, 2006 3:24 am Post subject: |
|
|
I've not run your code, but it'd be safer to use the C string functions, like:
sprintf(month, "%i", i)
instead of trying to directly manipulate a char array. This also ensures your string is zero-terminated (as long as 'month' is defined as char[3] or larger).
Personally I'd rework your loops so that the input side is split slightly from the display/calculation side, so you'd have
1. Display current month
2. Get input
3. Change month depending on input
4. Loop
instead of at the moment where you're reading inputs in the middle of displaying your screen information, but that's just a personal style I guess. _________________ CPCPSP [http://nige.the-pub.org/cpcpsp/] an Amstrad CPC emulator for the PSP |
|
| Back to top |
|
 |
Mortimus
Joined: 06 Jan 2006 Posts: 7
|
Posted: Sat Jan 07, 2006 3:59 am Post subject: y i use my print |
|
|
im using my print b/c it using a bitmap font, and displays over what I have, its not like the printf that displays debug info. _________________ ~ Mortimus ~ |
|
| Back to top |
|
 |
nullp01nter

Joined: 04 Jan 2006 Posts: 26 Location: Saxony/Germany
|
Posted: Sat Jan 07, 2006 6:46 am Post subject: |
|
|
| Quote: | | im using my print b/c it using a bitmap font, and displays over what I have, its not like the printf that displays debug info. |
This might be true, but what Nige suggested is not to prepare your string with that somehow ugly "if(i<10){month[0] = 32; month[1] = i+48; }else{month[0] = 49; month[1] = i+38;}" but with something more elegant. The recommended "sprintf" does not print to your screen, instead it outputs to the string buffer you specified. This way you are free to use all the printf features such as string output, integer, hex, floating point etc. and feed it to your own nifty text function. I don't know how your knowledge about printf is, but to clarify Nige's example: sprintf(month, "%i", i); fills your buffer "month" (which must be large enough) with the integer textual equivalent of what is inside your variable "i".
Thoralt |
|
| Back to top |
|
 |
Mortimus
Joined: 06 Jan 2006 Posts: 7
|
Posted: Sat Jan 07, 2006 7:17 am Post subject: oh thanx |
|
|
oh thanx, i never have used printf or sprintf before programming for psp, i didn't know that. _________________ ~ Mortimus ~ |
|
| Back to top |
|
 |
Mortimus
Joined: 06 Jan 2006 Posts: 7
|
Posted: Sat Jan 07, 2006 7:23 am Post subject: ok using that |
|
|
ok using that method, i don't need that stupid if then for first and 2nd digit.
The first set works fine (the month), but then when it gets to the day, it messes up still, it shows where month should be as "%" and the day as "%" and it doesnt change with button input. _________________ ~ Mortimus ~ |
|
| Back to top |
|
 |
nullp01nter

Joined: 04 Jan 2006 Posts: 26 Location: Saxony/Germany
|
Posted: Sat Jan 07, 2006 7:27 am Post subject: |
|
|
To find out more about printf and what types of data you can output with it you may want to have a look at http://en.wikipedia.org/wiki/Printf - they have a quite good summary there.
Thoralt |
|
| 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
|