optional parameters - sscanf
#1

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..
Reply
#2

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

Nvm.
Reply
#4

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.
Reply
#5

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.
Reply
#6

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?
Reply
#7

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.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)