Optional File: Parameter
#1

Hey guys.
Just creating a function where I need to have an optional File:Parameter. But how do I set it "optional"?
I can't set it to 0 or '\0' or some other NULL code, because it got the File:Tag.
What to do?

PS: I mean this (Searching for '?'):
pawn Код:
public Foo(var, File:moo = ?)
EDIT: Noticed that I could do it per {File,_}:... but I want to know this way though...
EDIT2: It's a bad way using getarg etc. ...
Reply
#2

It depends what you're trying to do with the handle. If you're trying to assign it to a handle, then you're going to have to do it inside the function, as when setting it to a default of the fopen() function, it crashed my compiler. In that case, the file handle won't stay with the handle that you pass to the function. For example:
pawn Код:
main( )
{
    new File: hi, i = 5;
    test( i, hi );
    printf( "OUTSIDE FUNC: %i", _:hi );
}

test( var, File: moo )
{
    moo = fopen( "test.ini", io_write );
    printf( "INSIDE FUNC: %i", _:moo );
}
Printed:
Код:
INSIDE FUNC: 5063776
OUTSIDE FUNC: 0
So if you're trying to have the tag from outside that function hold that file handles value, you'll have to add a & before the File: tag.

Or are you trying to do a whole other thing all together?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)