Need help with creating function
#1

Hi!
I've been thinking that its too complicated when you need to send only one formated message.
You have to create new string, then format it, and then send it. I though it would be better if you could do it in just one function.

I tried to make function to send formatted message (playerid, color, const message[], {Float,_}:...).
That allows you to give any amount of parameters at the end, but I don't know how to use the last parameters in function.
Is it possible? and if so, how?


PROBLEM SOLVED
Reply
#2

It is possible, i believe you have to use "getarg" - i will have a go now, it's something i've always wanted to play with, just never had reason

Код:
Ugh, This forum requires that you wait 120 seconds between posts. Please try again in 27 seconds.
I must type to fast, i'm sorry.

This forum requires that you wait 120 seconds between posts. Please try again in 1 seconds.
THAT WAS JUST MEAN
Reply
#3

pawn Код:
new
    str[150];
#define SendFormattedMessage(%1,%2,%3,%4); \
format(str, sizeof str, %3, %4); \
SendClientMessage(%1, %2, str);
Example
pawn Код:
new
    a = 3;
SendFormattedMessage(playerid, 0xffffffff, "Hello this is a formatted message look -> %d", a);
If you don't know how to use a function, I don't think you can create it correctly.
Reply
#4

Quote:
Originally Posted by Alby Fire
Посмотреть сообщение
pawn Код:
new
    str[150];
#define SendFormattedMessage(%1,%2,%3,%4); \
format(str, sizeof str, %3, %4); \
SendClientMessage(%1, %2, str);
Example
pawn Код:
new
    a = 3;
SendFormattedMessage(playerid, 0xffffffff, "Hello this is a formatted message look -> %d", a);
If you don't know how to use a function, I don't think you can create it correctly.
Can this handle more than one argument then?

(eg SendFormattedMessage(playerid, hex, "Test %s - you have %i", name, score);
Reply
#5

Ok thanks for replys.
Better to use macro than function.

Код:
new
    str[150];
#define SendFormattedMessage(%1,%2,%3,%4); \
format(str, sizeof str, %3, %4); \
SendClientMessage(%1, %2, str);
works
Reply
#6

Quote:
Originally Posted by Johnson_boy
Посмотреть сообщение
Ok thanks for replys.
Better to use macro than function.
Yes, it probably is - it looks more reliable than anything i've come up with (although it is working... )
Reply
#7

Try this script ......
i test this and i tell you it work or no!!
Reply
#8

It is better to use str[128] than str[150], because a line in the chatbox has only 128 characters...
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)