Making Unlimited string args for a function
#1

okay im trying to pass unlimited arguments to a function,
the hard part is getting the string from the argument

let my code explain,
this creates a db table with the fields passed to the function

but i keep getting an error
pawn Код:
stock CreateNewDbTable(tbl_name[],...)
{
    new str_Query[256];
   
    strcat(str_Query,"CREATE TABLE IF NOT EXISTS `");
    strcat(str_Query,tbl_name);
    strcat(str_Query,"` (");
   
    for (new i = 1,i_n_a=numargs(); i < i_n_a ; ++i)
    {
        if (i>2) strcat(str_Query,",");
        strcat(str_Query,"`");
        strcat(str_Query,getarg(i));//<~~~~type mismatch error here.
        strcat(str_Query,"`");
    }
   
    strcat(str_Query,")");
    db_query(j5ud,str_Query);
    return 1;
}
and i use it like so..
pawn Код:
CreateNewDbTable("USERS",
                    "NAME",
                    "PASSWORD",
                    "IP",
                    "ALIAS",
                    "EXP",
                    "LEVEL",
                    "FLAGS",
                    "SCORE",
                    "CASH",
                    "X",
                    "Y",
                    "Z",
                    "A",
                    "INTERIOR",
                    "VWORLD");
the pawn ref says getarg() can take a second argument

getarg(arg, index=0)

to indicate the start of an array
iv tried
pawn Код:
getarg(i,0)
but just get an argument type mismatch.

hoping someone can shed some light on this for me.
thanks
Reply
#2

Show me how u declare the new variable "getarg".


EDIT:

Disregard this statement, i just worked out it is an old native function.
Reply
#3

its part of the pawn language!

i made many functions like this in the past, but none of them took a string as an argument.


Edit:
ops yeah its part of pawns core.
Im thinking i will be told this is not possible without the string include...
Im not sure yet im still hunting for the info.
Reply
#4

I think this is what your looking for:
https://sampforum.blast.hk/showthread.php?tid=285759
Reply
#5

iv tried that!
also with that I would need to know the length of the string ahead of time,
which will defeat the function.

using
pawn Код:
getarg(i,0)
gives an argument type mismatch (argument 2)



EDIT:
I take that back that post did help
as it lead to this http://forum.sa-mp.com/showpost.php?...&postcount=534
and that was the solution

thanks!
Reply
#6

AFAIK, the correct method is

Код:
{Float,_}:...
Put that in your parameter list (to the very end), and it should accept infinite numbers of arguments. I am pretty sure you can't define just one of a kind of these infinite stuff.

Anyhow, I don't have a clue how to use them inside your function, I'm sure somebody knows the answer.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)