Passthru variables from function 1 to function 2 -
Programie - 14.04.2012
Hi,
I want to write a function which requires a dynamically amount of parameters and pass them to format.
I know that is possible using a macro. But I don't want to use a macro because I have to initialize a few variables which may get in conflict with other variables of the same name or if I have to call that function multiple times / use it in a loop.
Any way to solve that?
Re: Passthru variables from function 1 to function 2 -
Jonny5 - 14.04.2012
you mean something like this
pawn Code:
public Check_Bit(flags,{_}:...)
{
for (new i = 1; i < numargs(); ++i)
{
format(str,len,"%i",getarg(i));
}
return 1;
}
just an example and i start my loop at 1 as i have one other known argument.
Re: Passthru variables from function 1 to function 2 -
Programie - 14.04.2012
hmm... but that won't work for strings.
Example usage of my "passthru"-function:
Code:
MyFunction(message[], all, variables, to, pass, to, format)
{
// Some stuff like checks
format(myString, sizeof(myString), message, all, variables, to, pass, to, format);
return MyOtherFunction(myString);
}
Code:
MyOtherFunction(string[])
{
// Some code
if (a != b)
{
return false;
}
// More code
return true;
}
The problem is: I can not get the result of a function in a macro if there are multiple statements:
Code:
#define MyMacro(%0,%1) format(myString, sizeof(myString), %0, %1); MyOtherFunction(myString)
new myTestVar = MyMacro("This is a %s", "Test");// Won't work...
The code just gets translated to that:
Code:
new myTestVar = format(myString, sizeof(myString), "This is a %s", "Test"); MyOtherFunction(myString);
Or easier to read:
Code:
new myTestVar = format(myString, sizeof(myString), "This is a %s", "Test");
MyOtherFunction(myString);
Re: Passthru variables from function 1 to function 2 -
Jonny5 - 14.04.2012
i see so your wanting something like
pawn Code:
MyFunction(message[], ...)
{
// Some stuff like checks
format(myString, sizeof(myString), message, ...);
return MyOtherFunction(myString);
}
that wont work but i see what ya mean.
I dont know how to get ALL parameters and pass them in one go.
I guess you could load an array with them and pass that array..
Re: Passthru variables from function 1 to function 2 -
Programie - 14.04.2012
Quote:
Originally Posted by Jonny5
i see so your wanting something like
pawn Code:
MyFunction(message[], ...) { // Some stuff like checks format(myString, sizeof(myString), message, ...); return MyOtherFunction(myString); }
|
You got it.
Any way to check if an unknown parameter is a string or not?
Re: Passthru variables from function 1 to function 2 -
Jonny5 - 14.04.2012
im not sure this will work but you can try to
make your own tag for it
s_string:mystringvar[];
and use tagof() in the functions to check for the s_string: tag.
I dont think this will work with strings though because the function
is taking an array as an argument. And we both know a string is an array.
sorry I couldent be of more help
regards,
Re: Passthru variables from function 1 to function 2 -
Programie - 14.04.2012
Right, a string is just an array with characters.
Mhh maybe that works: Check the input string for % and the character after that. For example "%s" should be read as string, "%d" should be read as normal number (double/integer).
*Trying it*