SA-MP Forums Archive
Custom printf - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Custom printf (/showthread.php?tid=111744)



Custom printf - Tr1viUm - 03.12.2009

Hello!

I've been trying to make my own printf function that only gets called if debug mode is on. I however can't get them working with strings in it. I made them for integers and floats though but that's useless for me. I tried using getarg to use it at printf.

I read about making a #define to bypass this problem. It didn't work with the state machines at me. I'm not sure if it's even possible what I want but perhaps anyone knows more?

My code:
Код:
sprintf(const format[], {Float,_}:...) <debug:on>
{
	printf(format, getarg(1));
}



Re: Custom printf - Correlli - 03.12.2009

You mean something like this?

pawn Код:
new
    FALSE = 0;
pawn Код:
#define ConsoleMsg(%0,%1) \
do \
{ \
  new \
      string[128]; \
  if(strlen(%0) > 0) \
  { \
    format(string, sizeof(string), %0, %1); \
    print(string); \
  } \
} \
while(FALSE)



Re: Custom printf - Tr1viUm - 03.12.2009

No, that does not support the state machine (<debugn>).

I use this code for a custom print function. I need one that formats the print too.

pawn Код:
sprint(const string[]) <debug:on>
{
    print(string);
}



Re: Custom printf - Finn - 03.12.2009

pawn Код:
#define DEBUG
pawn Код:
#if defined DEBUG
    #define debug(%1) printf(%1)
#else
    stock asd() { }
    #define debug(%1) asd()
#endif
Use debug() as printf() and when you don't want the debug messages coming up, simply comment out #define DEBUG.


Re: Custom printf - Tr1viUm - 03.12.2009

Sorry for not mentioning it but I'm using a /debug command to put it on and off.


Re: Custom printf - MenaceX^ - 03.12.2009

Quote:
Originally Posted by Don Correlli
You mean something like this?

pawn Код:
new
    FALSE = 0;
pawn Код:
#define ConsoleMsg(%0,%1) \
do \
{ \
  new \
      string[128]; \
  if(strlen(%0) > 0) \
  { \
    format(string, sizeof(string), %0, %1); \
    printf(string); \
  } \
} \
while(FALSE)
I suppose you meant printf(string); to be print(string);.


Re: Custom printf - Tr1viUm - 03.12.2009

Quote:
Originally Posted by Y_Leѕѕ
YSI has a custom format system written in PAWN - take a look in there (YSI_format.own) to see how that's done. Otherwise look in the last two pages of the code optimisations topic for discussion on possible solutions on this problem (passing variable arguments along to varadic functions), there is some nice data there on opcode manipulation, but no solutions yet.
I was reading Code Optimisations before I posted this and as you said there is no solution yet.

Only remaining 'solution' is defines then.

Thanks for the help.


Re: Custom printf - Correlli - 03.12.2009

Quote:
Originally Posted by MenaceX^
I suppose you meant printf(string); to be print(string);.
Yes, edited.