Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Candle on Sat 11/06/2005 16:10:04

Title: Just wondered about some code
Post by: Candle on Sat 11/06/2005 16:10:04
Anyone seen some code to have a NPC ask a riddle and have an inputbox for the answer ?
Title: Re: Just wondered about some code
Post by: Ashen on Sat 11/06/2005 16:25:53
Yeah, once.

...

Oh, you want to see it too?
You just need to use the InputBox command (obviously), and StrComp (or StrCaseComp) to check the response, e.g.:


DisplaySpeech (NPC, "I am soft, yet I am firm,");
DisplaySpeech (NPC, "I am coloured, yet I am clear,");
DisplaySpeech (NPC, "I am Jelly.");
DisplaySpeech (NPC, "What am I?");
string answer;
InputBox ("What am I?", answer);
DisplaySpeech (EGO, "Are you %s?", answer);
if (StrCaseComp ("Jelly", answer)  == 0) { // Got right answer - would accept 'Jelly' or 'jelly'
  DisplaySpeech (NPC, "Yes. Yes I am.");
  // Or whatever
}
else { // Wrong answer
  DisplaySpeech (NPC, "No I'm not, try again.");
  // Or whatever
}

(Written for 2.6, but easy enough to change to 2.7)
Title: Re: Just wondered about some code
Post by: Candle on Sat 11/06/2005 16:29:21
Thanks Ashen . I still use 2.6
Title: Re: Just wondered about some code
Post by: monkey0506 on Sat 11/06/2005 20:21:36
DisplaySpeech (NPC, "I am soft, yet I am firm,");
DisplaySpeech (NPC, "I am coloured, yet I am clear,");
DisplaySpeech (NPC, "I am Jelly.");
DisplaySpeech (NPC, "What am I?");
string answer;
InputBox ("What am I?", answer);
DisplaySpeech (EGO, "Are you %s?", answer);
if (StrCaseComp ("Jelly", answer) == 0) { // Got right answer - would accept 'Jelly' or 'jelly'
  DisplaySpeech (NPC, "Yes. Yes I am.");
  // Or whatever
}
else { // Wrong answer
  DisplaySpeech (NPC, "No I'm not, try again.");
  // Or whatever
}

Just FYI, you forgot a parenthesis. ;)
Title: Re: Just wondered about some code
Post by: Ashen on Sat 11/06/2005 22:00:26
Deliberate mistake. Just keeping y'all on your toes.

Honest.

(Heh heh heh, smooth...)

Jeez, you've got good eyes, I just spent 5 minutes trying to figure out where from. Anyway, I doubt Candle (or anyone else) is likely to copy-paste that exact code, so it's no big thing.
Title: Re: Just wondered about some code
Post by: monkey0506 on Sun 12/06/2005 01:24:09
Heh. ;D  I noticed it the first time I was reading through. ;D

And BTW, I would have copied and pasted and edited. :D :P :D

Not trying to be perfect or anything, I mean, I know I make enough mistakes, just trying to help out. ;)

Edit:  I just noticed that the quote takes the formatting away.  I always forget about that.