checking strings...

Started by Captain Mostly, Wed 02/07/2003 15:00:38

Previous topic - Next topic

Captain Mostly

why is it that the code:

string KNARKNAR;
KNARKNAR = "fufu";
if(KNARKNAR == "fufu")
{
Display("POOPOO");
}

never prints the word POOPOO...
I can't get an if statement to read what's in a string variable properly! What am I doing wrong?!?! WHA WHA WHA!

SSH

Tchh! Try:
Quote
StrComp (string str1, string str2)

Compares the strings STR1 and STR2. Returns zero if they are identical, and non-zero if they are not

Using "==" tries to interpret the strings as numbers in some undefined way, no doubt.
12

Proskrito

and also StrCopy(KNARKNAR,"fufu"); instead of KNARKNAR="fufu". Remember that strings and ints behave differently.

Captain Mostly

OOPS! I just found Strcomp() in the instructions!!

You can delete this thread if you please as it turns out it was a stupid question!

My apologies!

Pumaman

What version of AGS are you using?

v2.55 shouldn't compile the above script - it should give you an error message telling you to use the StrCopy function instead.

SMF spam blocked by CleanTalk