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


Messages In This Thread
Making Unlimited string args for a function - by Jonny5 - 29.04.2012, 03:51
Re: Making Unlimited string args for a function - by warcodes_ - 29.04.2012, 04:00
Re: Making Unlimited string args for a function - by Jonny5 - 29.04.2012, 04:07
Re: Making Unlimited string args for a function - by StevenIceman - 29.04.2012, 04:10
Re: Making Unlimited string args for a function - by Jonny5 - 29.04.2012, 04:16
Re: Making Unlimited string args for a function - by Reynolds - 29.04.2012, 07:01

Forum Jump:


Users browsing this thread: 1 Guest(s)