Invalid string - 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: Invalid string (
/showthread.php?tid=618849)
Invalid string -
GoldenLion - 10.10.2016
Hi, what's the problem of the code below? I'm trying to make a dialog that shows injuries in DIALOG_STYLE_TABLIST_HEADERS.
Код:
new injuries[1000], string[64];
format(string, sizeof(string), "Weapon\tBody Part\tTimes Injured\n\");
I get these errors:
Код:
(913) : error 037: invalid string (possibly non-terminated string)
(913) : error 017: undefined symbol "Weapon"
(913) : error 029: invalid expression, assumed zero
(913) : fatal error 107: too many error messages on one line
Re: Invalid string -
Bolex_ - 10.10.2016
Try this
Код:
new injuries[1000], string[64];
format(string, sizeof(string), "Weapon\tBody Part\tTimes Injured\n");
Re: Invalid string -
Stinged - 10.10.2016
No need to use format for that:
Код:
new injuries[1000], string[64] = "Weapon\tBody Part\tTimes Injured\n\\";
The problem was because you have
\", which is an escaped
" (So you can have it inside of a string without cutting it off.
You have to escape \ if you want to use it (I did in my code)
Re: Invalid string -
GoldenLion - 10.10.2016
Thanks to both of you.
By the way Stinged, why can't I sometimes set strings like this, but I need to use format? Sometimes it just doesn't let me and gives me errors, format is the only way in this case. I've been always wondering why is it like this.
Re: Invalid string -
Stinged - 10.10.2016
Quote:
Originally Posted by GoldenLion
By the way Stinged, why can't I sometimes set strings like this, but I need to use format? Sometimes it just doesn't let me and gives me errors, format is the only way in this case. I've been always wondering why is it like this.
|
If the string was used in something like strcat, strins, format, etc... it can't be set like this.
By the way, if you want to set a string like that (And you can't do the way I did), you shouldn't use format.
Format should only be used when you want to replace specifiers (%i etc) with values.
What you can do is this:
Код:
string[0] = 0;
strcat(string, new string here);
Or you can use this
strcpy macro.
Код:
#define strcpy(%0,%1) strcat((%0[0] = '\0', %0), %1)
strcpy(string, new string here);
Re: Invalid string -
GoldenLion - 10.10.2016
Quote:
Originally Posted by Stinged
If the string was used in something like strcat, strins, format, etc... it can't be set like this.
By the way, if you want to set a string like that (And you can't do the way I did), you shouldn't use format.
Format should only be used when you want to replace specifiers (%i etc) with values.
What you can do is this:
Код:
string[0] = 0;
strcat(string, new string here);
Or you can use this strcpy macro.
Код:
#define strcpy(%0,%1) strcat((%0[0] = '\0', %0), %1)
strcpy(string, new string here);
|
Alright, thank you.