gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

DS development > consolePrintf ERROR

#53213 - jandujar - Tue Sep 06, 2005 8:25 pm

Hello,

I have a little problem. Here is my peace of code:

Code:

consoleInitDefault((u16*)SCREEN_BASE_BLOCK_SUB(31), (u16*)CHAR_BASE_BLOCK_SUB(0), 16);
   
int integer=9;
consolePrintf("Integer %d\n",&integer);


This make my game hangs.

This code hangs too:
Code:

consolePrintf("Integer %d\n",integer);



But I can write characters or strings without any problem.

What i'm doing wrong?

Another question I have is to know which are the rang of values of the function:
touchPosition tp;
tp=touchReadXY();
tp.x between ...... min and max
tp.y between ..... min and max
tp.px ""
tp.py ""
_________________
http://jandujar.homelinux.com
http://www.dsrobot.com

#53221 - falcon!!! - Tue Sep 06, 2005 9:05 pm

it should be this


consoleInitDefault((u16*)SCREEN_BASE_BLOCK_SUB(31), (u16*)CHAR_BASE_BLOCK_SUB(0), 16);

int integer=9;

consolePrintf("Integer %d\n",&integer);

#53222 - jandujar - Tue Sep 06, 2005 9:29 pm

??

This make mi game hangs.

Maybe a bug of ndslib?
_________________
http://jandujar.homelinux.com
http://www.dsrobot.com

#53223 - GPFerror - Tue Sep 06, 2005 9:35 pm

try something like this, at least I had to do this to get it to work in a some of the DS emulators for numbers.

char temp[100];
int integer=9;
sprintf(temp,"Integer %d",integer);

consolePrintf("%s\n",temp);

#53246 - cybereality - Wed Sep 07, 2005 12:22 am

You must be careful not to attempt to print variables that are not defined, it will hang. Here is the console code I am using and it works fine:
Code:

int current_image = 0;
const char* game_state = "title";

consoleInitDefault((u16*)SCREEN_BASE_BLOCK_SUB(31), (u16*)CHAR_BASE_BLOCK_SUB(0), 16);

consoleClear();
consolePrintf(" Frame: %d   \n", current_image);
consolePrintf(" GameState: %s   \n", game_state);
consolePrintf(" Touch x = %d      \n", IPC->touchXpx);
consolePrintf(" Touch y = %d      \n", IPC->touchYpx);

Also, I am calling the consolePrintf from the on_irq() function, not the main loop (check chris doubles tutorials if you are not doing this). There is no reason that a string would work and an int wouldn't as far as I know. You may have to cast the variable as an int before hand if you are using pointers or something like that. If you are still having problems you may want to look elsewhere in the code. Hope that helps.

// cybereality

#53315 - Ethos - Wed Sep 07, 2005 1:20 pm

falcon!!! wrote:
it should be this
consolePrintf("Integer %d\n",&integer);


Why would you print the address of that variable?? ....Not likely



The only problem I have found is that you should put terminating characters '\0' at the end of the string if you repeatedly show different sized values....the only time I had other problems is on emulators....is this on hardware??
_________________
Ethos' Homepage (Demos/NDS 3D Tutorial)

#53349 - jandujar - Wed Sep 07, 2005 7:44 pm

This code works fine

Code:

char temp[100];
int integer=9;
sprintf(temp,"Integer %d",integer);

consolePrintf("%s\n",temp);


Thank's
_________________
http://jandujar.homelinux.com
http://www.dsrobot.com