Adventure Game Studio

AGS Support => Advanced Technical Forum => Topic started by: Captain Mostly on Wed 02/07/2003 15:00:38

Title: checking strings...
Post by: Captain Mostly on Wed 02/07/2003 15:00:38
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!
Title: Re:checking strings...
Post by: SSH on Wed 02/07/2003 15:10:25
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.
Title: Re:checking strings...
Post by: Proskrito on Wed 02/07/2003 15:19:33
and also StrCopy(KNARKNAR,"fufu"); instead of KNARKNAR="fufu". Remember that strings and ints behave differently.
Title: Re:checking strings...
Post by: Captain Mostly on Wed 02/07/2003 17:36:42
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!
Title: Re:checking strings...
Post by: Pumaman on Wed 02/07/2003 22:40:44
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.