SA-MP Forums Archive
sscanf parameter problem - 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: sscanf parameter problem (/showthread.php?tid=546494)



sscanf parameter problem - Jonesy96 - 15.11.2014

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.


Re: sscanf parameter problem - Abagail - 15.11.2014

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.


Re: sscanf parameter problem - Jonesy96 - 15.11.2014

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.


Re: sscanf parameter problem - Abagail - 15.11.2014

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


Re: sscanf parameter problem - SickAttack - 15.11.2014

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



Re: sscanf parameter problem - Jonesy96 - 15.11.2014

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



Re: sscanf parameter problem - Kwarde - 15.11.2014

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)


Re: sscanf parameter problem - Jonesy96 - 15.11.2014

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


Re: sscanf parameter problem - Kwarde - 16.11.2014

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


Re: sscanf parameter problem - Jonesy96 - 16.11.2014

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.