Just wondered about some code

Started by Candle, Sat 11/06/2005 16:10:04

Previous topic - Next topic

Candle

Anyone seen some code to have a NPC ask a riddle and have an inputbox for the answer ?

Ashen

#1
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.:

Code: ags

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)
I know what you're thinking ... Don't think that.

Candle


monkey0506

#3
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. ;)

Ashen

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.
I know what you're thinking ... Don't think that.

monkey0506

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.

SMF spam blocked by CleanTalk