SA-MP Forums Archive
Unlimited function arguments: Fetching and passing the unchanged {Float,_}:... ? - 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: Unlimited function arguments: Fetching and passing the unchanged {Float,_}:... ? (/showthread.php?tid=144025)



Unlimited function arguments: Fetching and passing the unchanged {Float,_}:... ? - Kyeno - 25.04.2010

Hello there,

I'm willing to build dynamic, re-usable countdown functionality for my soon-to-come gamemode.

My first assumption were using the "unlimited arguments" function and passing the direct raw data into SetTimerEx(), after setting some local data. To make the long story short, and the overall algorithm much simplified, let's think of somehting like that:

Код:
Countdown_forPlayer(playerid, seconds, callback[], fmt[], {Float,_}:...) {

	new miliseconds = seconds * 1000;
	SetTimerEx(callback, miliseconds, false, fmt, {Float,_}:...); // this {Float,_}:... here is guesed and doesn't work
}
I figured out (with a little help from my friends; cheers TheAlpha ) that {Float,_}:... in function declaration actually allows me for the unlimited args, but then... how do i get the _raw_ data and pass anywhere further?

All i've seen around are numargs(), getarg() and setarg(), which obviously are not the case here. (unless i can grab those args with a loop, combine back together and put in the SetTimerEx() thingy; still not certain how would that be even possible)

I'd be really thankfull for any tips.

Cheers!


Re: Unlimited function arguments: Fetching and passing the unchanged {Float,_}:... ? - ¤Adas¤ - 25.04.2010

There is a way to do this, but it is very strange and hard. Better just use simple SetTimerEx...


Re: Unlimited function arguments: Fetching and passing the unchanged {Float,_}:... ? - Kyeno - 25.04.2010

Well, using 'just SetTimerEx' is deffinitely not the case; the lines i pasted are just an example; i'm going for much more advanced functionality inside the function.


Re: Unlimited function arguments: Fetching and passing the unchanged {Float,_}:... ? - dice7 - 25.04.2010

The functions are called numarg, getarg and setarg.
Here's a tut
http://forum.sa-mp.com/index.php?topic=101773.0


Re: Unlimited function arguments: Fetching and passing the unchanged {Float,_}:... ? - Kyeno - 26.04.2010

I know (and mentioned it myself), but still i'm asking how to get all the arguments in one "variable" (or any other form) to be able to pass it raw into the inner SetTimerEx() function?


Re: Unlimited function arguments: Fetching and passing the unchanged {Float,_}:... ? - dice7 - 26.04.2010

Something like this then ?
pawn Код:
#define Countdown_forPlayer(%1,%2,%3,%4,%5) new FALSE = 0; do {new miliseconds=%2*1000; SetTimerEx((%3),miliseconds,0,(%4),%5); printf("%d",miliseconds);} while(FALSE)
Note that I don't quite understand why you need to declare a new variable FALSE (or whatever name) and set it to 0, because if using only 0 in the do-while, the code will error on compile


Re: Unlimited function arguments: Fetching and passing the unchanged {Float,_}:... ? - Kyeno - 26.04.2010

Hi,

Thanks again for Your effort, it looks pretty nice.

But still not much of a clue how do i insert other functionalities inside? :>
Your example looks like just SetTimerEx() replacement, and thus i want to pluck some functionality in AND THEN call SetTimerEx() at the end