passing all undefined amout of parameters to another function?
#1

Код:
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?
Reply
#2

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.
Reply
#3

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

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
Reply
#5

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
Reply
#6

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;
}
Reply
#7

Код:
---
\..\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.
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)