String length cut-off?
#1

Well since recently I've noticed that on my commands, the string has been cut off. For example, commands that give a reason, like kick, ban, mute, warn, etc. Now the reason string has been cut off for a reason I don't know, I'm wondering if it has anything to do with sscanf 2.0 since I just updated to that.

Yes I've made the reason string bigger and it doesn't work (made it up to 200 cells, instead of the normal 100)
Here's what it looks like:



Chatlog:

Код:
[20:55:07] Tee has been warned by Admin Tee for: Warning test. This is testing t (1 / 3 warnings).
[20:55:07] You have been warned by Admin Tee for: Warning test. This is testing t
Here's what I typed:

Код:
/warn tee Warning test. This is testing the lenght of the string which should be 128 characters and maybe it's not. Test warn...
Reply
#2

We can't help you unless you post the command...
Reply
#3

You can't show more than 128 (or 127?) characters in a client message. There is no way to get around this. If it's longer, it will not show. You HAVE to cut stuff off when you have user-input strings in the messages. This can be done like so:

pawn Код:
new scm[128];
format(scm, sizeof(scm), "%s warned %s for %s.", blah, blah, blah);
You could set a limit for the reason by using strlen() on both players' names, plus the characters in the string, take that away from 128 and you have the reason limit. Example:

MP2 has warned Tee for 'hacking'.

MP2 = 3
Tee = 3
Rest of string = 20 (+1 null char = 21)

Total = 21+3+3 (27)
Reason limit = 128-(strlen(name1)+strlen(name2)+21) [101]

pawn Код:
if(strlen(reason) > reason_limit) return SendClientMessage(playerid, red, "ERROR: Reason too long.");
Note that color embedding also counts, it will add 8 characters to a string. I recommend not using embedding when user-input strings are used. unless they are going to be short.
Reply
#4

Do you use sscanf at all?
Reply
#5

The problem started when I upgraded to sscanf 2.0. I've never changed my command.
Here's the sscanf line anyway:

pawn Код:
if(sscanf(params,"us", id,rson))return SendClientMessage(playerid, Grey, "Usage: /warn [id] [reason]");
It only sent 33 characters from the reason string of 187 characters.

Again, this is how it was on previous version of sscanf, although I'm not yet sure if that's the problem.
Reply
#6

There is a limit for characters in 1 line.
When chatting, it automatically splits it into 2 lines. ; )
Reply
#7

Look at the picture again and you'll see that's not the problem.
Reply
#8

pawn Код:
#DEFINE MAX_STRING 1024
or
pawn Код:
new string[256]
Check if your MAX strings are set to 1024 or your string created at that command has a small number "256" would be good I think.
Reply
#9

Well then it's the formatting.
Reply
#10

You need to specify a string size when you use 's' in sscanf.

An example of this is:
pawn Код:
new szParams[128], iSomething;
if(sscanf(params, "us[128]",  iSomething, szParams))
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)