[Include] SetPlayerPosEx
#11

Quote:
Originally Posted by ******
Посмотреть сообщение
OK, I need to make clear the difference between "definition" of a function and "calling" a function:

pawn Код:
MyFunc(a, b = 27, c[] = "Hi")
{
    printf("%d %d %s", a, b, c);
}
That is a function "definition", with one required parameter and two optional parameters. The first defaults to 27, the second to "hi". These, on the other hand, are function calls:

pawn Код:
MyFunc(); // Warning (required parameter is missing).
MyFunc(42); // Prints "42 27 hi".
MyFunc(42, 42); // Prints "42 42 hi".
MyFunc(42, 42, "hello"); // Prints "42 42 hello".
Now it may be that you want to change the third parameter, but leave the second as default. There are three ways of doing this AT THE CALL SITE:

pawn Код:
MyFunc(42, 27, "hello"); // Prints "42 27 hello".
MyFunc(42, _, "hello"); // Prints "42 27 hello".
MyFunc(42, .c = "hello"); // Prints "42 27 hello".
The first version is not brilliant, if the default value on the function definition changes, this will continue to print "27" instead of the new default value.

The second version uses "_" to mean "default", with the parameters still specified in order.

The third version doesn't mention the second parameter at all, instead it sets the third parameter by name using ".".

Named parameters do not have to be in order:

pawn Код:
MyFunc(42, .c = "hello", .b = 42); // Prints "42 42 hello".
Hopefully that clears up my last post.
Wow that seriously clear's the fact. So named parameters can be called in any order. But other's params need to be ordered according to the definition!

Params are missing warning! Thats a new thing. Wow i learnt lot of stuff about Programming today. Thanks alot bro!

You're the Boss!
Reply


Messages In This Thread
SetPlayerPosEx - spsx.inc v1.1 - by Ballu Miaa - 28.02.2012, 09:12
Re: SetPlayerPosEx - by iTorran - 28.02.2012, 09:18
Re: SetPlayerPosEx - by Ballu Miaa - 28.02.2012, 09:22
Re: SetPlayerPosEx - by Ballu Miaa - 28.02.2012, 10:00
Re: SetPlayerPosEx - by Ballu Miaa - 28.02.2012, 11:04
Re: SetPlayerPosEx - by [HK]Ryder[AN] - 28.02.2012, 11:09
Re: SetPlayerPosEx - by Shadow_ - 28.02.2012, 11:16
Re: SetPlayerPosEx - by Niko_boy - 28.02.2012, 12:42
Re: SetPlayerPosEx - by Ballu Miaa - 28.02.2012, 12:50
Re: SetPlayerPosEx - by Y_Less - 28.02.2012, 13:04
Re: SetPlayerPosEx - by Ballu Miaa - 28.02.2012, 13:23
Re: SetPlayerPosEx - by legodude - 28.02.2012, 20:05
Re: SetPlayerPosEx - by Ballu Miaa - 29.02.2012, 02:26
Re: SetPlayerPosEx - by willzyyy - 29.02.2012, 04:01
Re: SetPlayerPosEx - by Ballu Miaa - 29.02.2012, 05:20
Re: SetPlayerPosEx - by Jochemd - 16.03.2012, 13:38
Re: SetPlayerPosEx - by Ballu Miaa - 16.03.2012, 16:45
Re: SetPlayerPosEx - by kacper55331 - 16.03.2012, 21:14
Re: SetPlayerPosEx - by Ballu Miaa - 23.03.2012, 00:40
Re: SetPlayerPosEx - by Krx17 - 23.03.2012, 00:56
Re: SetPlayerPosEx - by Crazymax - 29.04.2012, 17:54
Respuesta: SetPlayerPosEx - by irinel1996 - 29.04.2012, 22:11
Re: SetPlayerPosEx - by lucas_mdr1235 - 29.04.2012, 22:39
Re: SetPlayerPosEx - by rscaerzx - 29.04.2012, 23:42
Re: SetPlayerPosEx - by Ballu Miaa - 30.04.2012, 16:00
Re: SetPlayerPosEx - by FalconX - 01.05.2012, 19:35
Re: SetPlayerPosEx - by Ballu Miaa - 02.05.2012, 02:05

Forum Jump:


Users browsing this thread: 11 Guest(s)