Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: poc301 on Fri 05/11/2004 20:05:57

Title: Extremely simple IF command driving me nuts.. Help please (SOLVED)
Post by: poc301 on Fri 05/11/2004 20:05:57
I have been working for 20 minuts on this INCREDIBLY simple code snippet that isn't working...Ã,  Any help would be appreciated :(

CODE:

// script for room: First time player enters screen

string class;

GetGlobalString(17,class) ;Ã,  /This should be the word Warrior

if (class == "Warrior")

{
display ("IT WORKED!");


}

Display("It didn't work... %s", class);


---------------------

Now, the thing doesn't work, as it skips right on through to the bottom line "It didn't work... %s", class line.

When that bottom line is run, it reads :

It didn't work... Warrior

So I know the Global string is being pulled out properly, but for some reason my IF statement isn't working.. ARGH!

I would greatly appreciate any help.

Thanks,

Bill Garrett
Ã, 
Title: Re: Extremely simple IF command driving me nuts.. Help please
Post by: Hellomoto on Fri 05/11/2004 21:38:06
Your display didn't have a capital
Title: Re: Extremely simple IF command driving me nuts.. Help please
Post by: Janik on Fri 05/11/2004 21:43:13
Your comment

GetGlobalString(17,class) ;  /This should be the word Warrior

is missing a slash:

GetGlobalString(17,class) ;  //This should be the word Warrior

Also, you'll want to put an "else" before displaying "it doesn't work".
Title: Re: Extremely simple IF command driving me nuts.. Help please
Post by: poc301 on Fri 05/11/2004 22:26:42
The // thing was done as I was posting it here on the forum.  That comment isn't in the real code.  I just wanted to clarify for anyone looking at it.

I put the 'else' in, and I also made it 'Display'. 

Still having the same problem.  The global variable does have Warrior in it, but the IF statement isn't working :(

Any other ideas?

Thanks,

Bill Garrett
Title: Re: Extremely simple IF command driving me nuts.. Help please
Post by: Hellomoto on Fri 05/11/2004 22:55:39
It might not work, but try looking up strcomp in the manual. I think it has something to do with the fact that strings are not actual variables, but arrays, so you have to use a special function to check if to strings are equal.

In AGS, I think its strcomp, but I might be wrong.
Title: Re: Extremely simple IF command driving me nuts.. Help please
Post by: poc301 on Fri 05/11/2004 23:42:16
I resolved my issue with a backwards workaround :)

I created an INT of 1,2,3,4 (one for each class), that I can use to determine which view the EGO will use.

I then did a backwards workaround (if globalblahblah(1) then doohickie= "Warrior") 

So I have everything working great now.

Thanks guys!

Bill Garrett
Title: Re: Extremely simple IF command driving me nuts.. Help please (SOLVED)
Post by: Proskrito on Sat 06/11/2004 14:20:58
you can not compare strings with '==', use the functions StrComp or StrCaseComp instead. You can see the details of these functions in the manual. Hope it helps : )