SA-MP Forums Archive
passing all undefined amout of parameters to another function? - 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: passing all undefined amout of parameters to another function? (/showthread.php?tid=154673)



passing all undefined amout of parameters to another function? - JernejL - 14.06.2010

Код:
stock SetTimerEx2(funcname[], interval, repeating, const format[], {Float,_}:...) {
	
	// do magic timer tracking here
	
	return SetTimerEx(funcname, interval, repeating, format, ... ?!?!? );
}
You see the dilemma.. i want to have a custom settimerex version, to track timer usage, but i haven't got a clue how to forward all parameters given to it to the original settimerex funcion.

Any ideas on how to accomplish this?



Re: passing all undefined amout of parameters to another function? - Simon - 14.06.2010

Hey, if you just want to track timer usage than it'd be easy to use a define.

pawn Код:
#define SetTimerEx2(%1,%2,%3,%4,%5)\
  (printf("Timer for %s started", %1) & SetTimerEx(%1,%2,%3,%4,%5))
"return" of SetTimerEx2 will be 0 if any return 0.. you can of course change that. The %5 contains everything in the "...", which if you don't want to do anything for the specific items should be fine.

It's not the ideal way and it's ugly, but it can work for you.


Re: passing all undefined amout of parameters to another function? - JernejL - 14.06.2010

I guess that approach is also valid lol, i'll try that, thanks.



Re: passing all undefined amout of parameters to another function? - Simon - 15.06.2010

The real solution is quite difficult to comprehend. You may find this post of use if you wish to spend a little more time working it out and editing for your purpose. I believe there is no other language feature that will help you do it easily:

http://forum.sa-mp.com/index.php?top...2209#msg902209


Re: passing all undefined amout of parameters to another function? - JernejL - 15.06.2010

This won't work.. i specifically need the timer id returned from settimerex, and do something with it. :/ most use of settimer is direct assignment, where i can't squeeze any code into that



Re: passing all undefined amout of parameters to another function? - Simon - 15.06.2010

Some more language hack theories, trying to make it so it can be used like a normal function: (i.e. new var = SetTimerEx2(..); )

pawn Код:
// multiply other function results by 0 and then add SetTimerEx.
#define SetTimerEx2(%1,%2,%3,%4,%5)\
  ((printf("Timer for %s started", %1) + other_func() * 0) + SetTimerEx(%1,%2,%3,%4,%5))
pawn Код:
// re-route the timerid and name to a function to do more code easily
#define SetTimerEx2(%1,%2,%3,%4,%5)\
  (__timer_ex(%1,SetTimerEx(%1,%2,%3,%4,%5)))

stock __timer_ex(name[], timerid)
{
  print("Timer %s has started with an ID of %d", name, timerid);

  return timerid;
}



Re: passing all undefined amout of parameters to another function? - JernejL - 15.06.2010

Код:
---
\..\test\test,inc(1056) : fatal error 103: insufficient memory


Errors: 1
The pawn compiler was unable to precompile.. aborting.
I get that whenever i try to compile your hack at first settimerex encountered.

EDIT: apparently just 1 timer.. because it has so many parameters it was wrapped into multiple lines with \ - it works if it's all in one line.