Passthru variables from function 1 to function 2
#1

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?
Reply
#2

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

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);
Reply
#4

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

Quote:
Originally Posted by Jonny5
View Post
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?
Reply
#6

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

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*
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)