Author Topic: Determining a String Value  (Read 2193 times)

0 Members and 1 Guest are viewing this topic.

Offline Doan Sephim

Determining a String Value
« 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?


Artificial Intelligence Competition

Offline Collector

Re: Determining a String Value
« Reply #1 on: December 02, 2013, 01:01:01 AM »
Can't you simply do an If Else statement?
KQII Remake Pic

Offline Doan Sephim

Re: Determining a String Value
« Reply #2 on: December 02, 2013, 08:32:08 AM »
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:
Code: [Select]
(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.

Offline Collector

Re: Determining a String Value
« Reply #3 on: December 02, 2013, 09:45:17 AM »
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.
KQII Remake Pic

Offline Doan Sephim

Re: Determining a String Value
« Reply #4 on: December 02, 2013, 03:37:36 PM »
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.
« Last Edit: December 02, 2013, 04:30:49 PM by Doan Sephim »
Artificial Intelligence Competition

Offline Collector

Re: Determining a String Value
« Reply #5 on: December 02, 2013, 05:10:43 PM »
Not sure about it in SCI, but it in other languages it would be a simple boolean check, something like:

Code: [Select]
         if (StrCmp(StringVariable1, StringVariable2) == 0) {
                PrintOK()
          }
« Last Edit: December 02, 2013, 05:13:16 PM by Collector »
KQII Remake Pic

Offline Doan Sephim

Re: Determining a String Value
« Reply #6 on: December 02, 2013, 06:30:18 PM »
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:
Code: [Select]
(if(== (StrCmp(@stringName "hello"))0)PrintOK())This code will print "OK" when the word entered by the player is "hello"

Offline Collector

Re: Determining a String Value
« Reply #7 on: December 02, 2013, 07:39:54 PM »
Might be nice to add this to the Wiki, perhaps in some generalized article about strings? The Studio help file is a little barren.
KQII Remake Pic


SMF 2.0.14 | SMF © 2017, Simple Machines
Simple Audio Video Embedder

Page created in 0.088 seconds with 23 queries.