Properly get string -
mads232 - 01.03.2015
Of what I've read, you make a string by making an array.
Let's say
Then you store strings in this. Let's say
Код:
newString = "Hello everybody";
But how do you GET this string then?
newString[0] will get the first letter, but how do you get the whole "Hello everybody"
Am I doing strings wrong, or am I just a noob? :P
-Thanks in forwards
Re: Properly get string -
Vince - 01.03.2015
Just "newString". No index necessary.
Re: Properly get string -
mads232 - 01.03.2015
Quote:
Originally Posted by Vince
Just "newString". No index necessary.
|
Thanks for replying. The problem is, that gives me the error 033: array must be indexed.
Re: Properly get string -
ArchB42 - 01.03.2015
Hello,
Here's a simple example to show you how it works.
Код:
// We create a string and put "Hello" inside.
// Note: We need 6 cells because there is an end-of-string caracter at the end ("\0").
new sText[6] = "Hello";
// Now we can show the string using functions:
printf("%s buddy", sText);
// It will render as: "Hello buddy"
Hope I helped. If you still have problems after that, please show us the portion of code you're trying to run.
Re: Properly get string -
mads232 - 01.03.2015
Quote:
Originally Posted by ArchB42
Hope I helped. If you still have problems after that, please show us the portion of code you're trying to run.
|
Hello

Thanks, I already read that one. So as it didn't really help me, here's an example:
I'm creating this:
OnPlayerChangeAnim(playerid, newAnim, oldAnim)
Whenever I want to compare newAnim to an anim, I do this:
Код:
new baseballBat[32];
baseballBat = "BASEBALL_BAT_1";
if(strcmp(baseballBat == newAnim)
{}
Then it tells me that baseballBat in the strcmp should be indexed. When I do baseballBat[0], I get no errors, because it of course is indexed then.
So how do I strcmp the whole String like this? Should I format baseballBat?
Re: Properly get string -
HazardouS - 01.03.2015
Hold on a second. That is not the correct strcmp syntax. Do it like this:
pawn Код:
if(!strcmp(baseballBat, newAnim, true)) //true means that we don't care about the capital letters (for example, test is identical to TeSt)
{
//they are identical
}
else
{
//they are not identical, at least one character is different
}
This is the wiki page:
https://sampwiki.blast.hk/wiki/Strcmp
Re: Properly get string -
mads232 - 01.03.2015
Quote:
Originally Posted by HazardouS
Hold on a second. That is not the correct strcmp syntax. Do it like this:
pawn Код:
if(!strcmp(baseballBat, newAnim, true)) //true means that we don't care about the capital letters (for example, test is identical to TeSt) { //they are identical } else { //they are not identical, at least one character is different }
This is the wiki page: https://sampwiki.blast.hk/wiki/Strcmp
|
!strcmp would be != and I want ==, therefore strcmp, right?..
Also true is optional, and I choose that it should care for capital letters
Re: Properly get string -
CalvinC - 01.03.2015
You don't use == or != in strcmp, the code he provided will check if baseballBat and newAnim matches correctly, but yeah you can change the "true" to "false" if it should care for capital letters.
Re: Properly get string -
mads232 - 01.03.2015
Quote:
Originally Posted by CalvinC
You don't use == or != in strcmp, the code he provided will check if baseballBat and newAnim matches correctly, but yeah you can change the "true" to "false" if it should care for capital letters.
|
I mean the ! in front of strcmp would check if they DIDN'T match?
Re: Properly get string -
HazardouS - 01.03.2015
In an if-statement, !variable means "variable == 0". Strcmp returns 0 when the strings match, so !strcmp means match. When you say if(variable), it actually means if(variable != 0), so "if( strcmp(string1, string2) )" is true when string1 and string2 do NOT match.