Optional File: Parameter - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (
https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Optional File: Parameter (
/showthread.php?tid=272389)
Optional File: Parameter -
Meta - 28.07.2011
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. ...
Re: Optional File: Parameter -
Grim_ - 28.07.2011
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?