Imitating the printf function in pawn
#1

I've never done this before; I was actually trying to make a ConsoleMessage() function that allows me to send parameters to it and then display it on the console by using print().

Like in the following example:
pawn Код:
ConsoleMessage("It's %d A.M.", 12);
How would I do that?

I tried the following but it just didn't work, I'm actually having a hard time trying to figure out what to do here:
pawn Код:
ConsoleMessage(message[], const format[], ...) {
    new string[256];
    strformat(string, sizeof(string), false, "%s", message); //This is plain wrong, it won't format the string with the extra params. "..."
    //This is where I'm getting lost, I don't know what to do in this function
    print(string); //This will just display "It's %d A.M." and not "It's 12 A.M."
}
Thanks in advance.
Reply
#2

Just use printf function.

https://sampwiki.blast.hk/wiki/Printf
Reply
#3

Quote:
Originally Posted by HardRock
Посмотреть сообщение
Just use printf function.

https://sampwiki.blast.hk/wiki/Printf
I'm sorry, but that's not what I'm trying to do. I just want to re-make the function in pawn, to learn how to send format params, format a string and display it, in this case, ConsoleMessage being the function receiving the format params.
Reply
#4

YSI/y_va does exactly what you are looking for.

http://ysi.wikia.com/wiki/Library:YSI%5Cy_va
https://sampforum.blast.hk/showthread.php?tid=399069
Reply
#5

First choice == y_va ^ as of Mellnik said.
Second choice == "getarg"
Reply
#6

Thanks, it's resolved.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)