Community
SCI Programming => SCI Syntax Help => Topic started by: Doan Sephim on December 01, 2013, 09:38:45 PM
-
I have recently hit a snag on my coding. Hopefully someone can help me with this.
I want to have the player type in a word using EditPrint. OK, that's easy enough. I pass the response to a string @stingName.
OK, now I want to check to see if stringName is the correct word. What kind of syntax would that take? I remember QFG1 did something like this at Erasmus' Castle with the imp asking 3 questions. Any ideas?
-
Can't you simply do an If Else statement?
-
Can't you simply do an If Else statement?
I have tried a couple of ways, but neither of them have worked yet.
First I coded it this way:
(if(Said('use/goggles'))
(if(send gEgo:has(INV_GOGGLES))
EditPrint (@stringName 14 "Which name would you like to locate?" #at -1 20 )
(if(== @stringName "jimbo")PrintOK()) // not sure how to code to check the string...I have tried it with the @ and without, but I cannot get the PrintOK() command to trigger.
I also tried (if(Said('jimbo')) in response to the EditPrint, but that also was ineffective.
-
How about placing a print statement to display the string before the final if? If it does not trigger, at least you could keep moving the print up before each successive if to see where it is failing.
-
How about placing a print statement to display the string before the final if? If it does not trigger, at least you could keep moving the print up before each successive if to see where it is failing.
I know that the string will hold the word the player types in...I just don't know how to then check if their word is the "right" one or not. It's quite simple to do with numbers, but when it comes to word strings I don't know if I can even use the mathematic operators like == to check it.
Gumby pointed me to this function a while ago when I was coding a similar thing. It's the StrCmp() function. I've tinkered a bit with it and honestly I'm still not quite sure how it works yet...but I am hoping it will yield the answer I am looking for. Hopefully someone with more coding knowledge can enlighten me a bit.
-
Not sure about it in SCI, but it in other languages it would be a simple boolean check, something like:
if (StrCmp(StringVariable1, StringVariable2) == 0) {
PrintOK()
}
-
Ah yes! Your syntax is a little wonky for SCI, but your idea is correct. I got it to work now thank you so much!
Here is my code for anyone who needs it spelled out more clearly:
(if(== (StrCmp(@stringName "hello"))0)PrintOK())This code will print "OK" when the word entered by the player is "hello"
-
Might be nice to add this to the Wiki, perhaps in some generalized article about strings? The Studio help file is a little barren.