Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: That Guy on Sat 27/08/2005 02:12:34

Title: An odd string comparison issue
Post by: That Guy on Sat 27/08/2005 02:12:34
Okay, so I did something similar to the following (in the interaction script of an inventory object called iCyberLink);

string text, trigger, name;

command.getText(text);  // this gets the text of a GUI label

iCyberLink.getName(name);  // this gets the name of the object

StrFormat(trigger, "Use %s", name);  //this formats trigger so it reads "Use CyberLink"

if (StrComp(trigger, text) == 0)
{
   // run interaction for object if text reads "Use CyberLink"
}

Trouble is, both StrComp and StrCaseComp refuse to return 0 (indicating identical strings) when I compared trigger and text.  In fact, in no way, shape, or form could I get any combination of a literal ("Use CyberLink") and/or a variable containing the string ("Use CyberLink") to compare against a second variable containing the same text.  I even printed out both strings prior to comparing them and they did in fact have the same text in them, and in my eye, should have returned a match.

What am I overlooking?
Title: Re: An odd string comparison issue
Post by: monkey0506 on Sat 27/08/2005 02:22:19
Hmm...I have had problems which are...somewhat remotely similar to this.  Try cutting the code out of your game, saving and exiting AGS, then pasting this in:

string textbuf;
string trigbuf;
string namebuf;

StrCopy(textbuf, "");
StrCopy(trigbuf, "");
StrCopy(namebuf, "");

command.GetText(textbuf);
iCyberLink.GetName(namebuf);
StrFormat(trigbuf, "Use %s", namebuf);

Display("trigbuf = %s. textbuf = %s.", trigbuf, textbuf);

if (!StrComp(trigbuf, text)) {
  }

Display("trigbuf = %s. textbuf = %s", trigbuf, textbuf);


Don't ask why I changed the names of the strings at this point...just try out what I suggested and let me know if it works...otherwise...Sorry I couldn't help.