sscanf parameter problem
#1

I've had an issue with sscanf regarding the below:

Код:
if(sscanf(params, "{s[7]}i", houseid)) return SendClientMessage(playerid, COLOR_GREY, "USAGE: /ah(ouse) setexit [id]");
Basically. The command is /ahouse setexit [id]

When I run the command without the id, so just "/ahouse setexit" it comes up with the error message. However, if I enter a house idea, so "/ahouse setexit 6" for example, then the code beyond the line above isn't executed at all.

Literally, if the id is entered with the command, it just breaks at this sscanf line.

Any ideas?

Thanks.
Reply
#2

Try this
pawn Код:
if(sscanf(params, "s[7]i", houseid)) return SendClientMessage(playerid, COLOR_GREY, "USAGE: /ah(ouse) setexit [id]");
I haven't really read up on advanced sscanf usage/usages beyond the normal but I don't believe curly brackets have a purpose, and probably mess up sscanf. Could be wrong though.
Reply
#3

The curly braces are there for 'silent parameters'. That's on the 'setexit' part of the command. By silent, I mean sscanf basically ignores whatever is inside the curly braces. Without them then 'setexit' would be attempted to be stored inside houseid surely.

Anyway, tried it none the less to no avail.
Reply
#4

Perhaps it's an issue beyond the line with sscanf? Can you show the rest of the code?
Reply
#5

pawn Код:
if(sscanf(params, "{s}i", houseid))
Reply
#6

Quote:
Originally Posted by Abagail
Посмотреть сообщение
Perhaps it's an issue beyond the line with sscanf? Can you show the rest of the code?
It's not. It's definitely that sscanf line because ive tested without that line, and the command works.

None the less, here you go:

Код:
FIXED
Reply
#7

You could also use sscanf(params, "s[11]I(-1)", szOption, houseid)
Then on 'create' and 'reload' just don't use the houseis. Under 'setexit', check if the houseid is -1 or not. If it's -1, send an usage message . Otherwise just process the command futher (but I guess you know how it works haha)
Reply
#8

I have it working. Began to realise the entire way I built up the command was wrong. Nothing wrong with the sscanf. Thanks all.
Reply
#9

Now I am curious.. how did you do it this time?
Reply
#10

Quote:
Originally Posted by Kwarde
Посмотреть сообщение
Now I am curious.. how did you do it this time?
Basically, I realised the command was reading "setexit 6" for example as 1 parameter, as opposed to 2. This was because I was only checking with sccanf for the ID parameter inside the "setexit" if statement. As a result, the "setexit" if comparison wasn't turned to true when an ID was passed as it read it as "setexit 6". Therefore, the functionality inside that if statement wasn't even ran. It's hard to explain so sorry if I confused you.

I had to restructure the command and set a default value for the ID parameter using sscanf before any of the if comparisons for "create", "setexit", etc.

I realise that's not well explained, but I can't really explain it without showing the old and new code haha.
Reply


Forum Jump:


Users browsing this thread: 4 Guest(s)