SA-MP Forums Archive
optional parameters - sscanf - 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)
+--- Thread: optional parameters - sscanf (/showthread.php?tid=485460)



optional parameters - sscanf - fordawinzz - 04.01.2014

Tried with this:
pawn Код:
if(sscanf(params, "iiI(0)i", param1, param2, param3, param4))
return SendClientMessage(playerid, -1, "Usage: /command [number of ... (1 or 2)] [param2] [param3] (this is optional, if param1 is setted to 2 then isn't) [param4]
but it doesen't work..


Re: optional parameters - sscanf - RedFusion - 04.01.2014

How do you mean when you say that it doesn't work?


Re: optional parameters - sscanf - J4mmyHD - 04.01.2014

Nvm.


Re: optional parameters - sscanf - fordawinzz - 04.01.2014

well, when the optional param is set to 2, it does work okay. when it's set to 1, it keeps sending me the syntax message.


Re: optional parameters - sscanf - Konstantinos - 04.01.2014

It does work fine for me.

/command 2 4 2 6 -> (no syntax message)
/command 2 4 1 6 -> (no syntax message)

As long as you type 4 numbers is fine but the optional will fail because it should be at the end.

Let's say you type: /command 2 4 1

It will take 1 as the third parameter (the optional one) and the param4 will be empty; thus the syntax will be displayed.


Re: optional parameters - sscanf - fordawinzz - 04.01.2014

If I use this: /command 1 4 160 -> syntax
but if I use this: /command 2 4 1 160 -> no syntax, works perfectly.

can't that parameter be passed somehow when it's in the middle?


Re: optional parameters - sscanf - Konstantinos - 04.01.2014

Read my post again - not using 4 numbers will display the syntax. The optional number should be the last parameter so you can use 3 numbers and the last one will be by default the value you specified.

pawn Код:
if(sscanf(params, "iiiI(0)", param1, param2, param3, param4))
/command 1 4 160

param1 = 1
param2 = 4
param3 = 160
param4 = 0 (by default since not any value was given)

I'm not sure if there's any way to be in the middle, it'll be better to post to sscanf's thread to be sure.