Author Topic: How can I let NPC Memorize all words and repeat what player said? (Solved)  (Read 242 times)  Share 

I'm working now on a very difficult code now.




This is the text from when Larry in the "Leisure Suit Larry 1" is in the shop (Quick Mart) where he can buy condom and other stuff. ,)

I know already I need to add this in the player interact when he touch the object.

Larry:
After looking around to make certain you're alone, you quietly ask the clerk if the has any available behind the counter.

The Clerk:
'Sure, we got lubbers!'

Narrator:
(Obviously you've hit his area of expertise!)

Clerk;
'What kind of lubber you want? Smooth or libbed?'


Now here is my problem. Larry has to choose the kind of condom

Then the Clerk ask Larry 

'Colored or plain?'

then the clerk ask Larry

'Lubricated or rough-cut?'

and again he ask Larry

'Striped or plaid?'

and for last time he ask Larry

'Peppermint or spearmint flavor?'

Then after that he says

'Oakie, doakie Meester!'

'Hey, everybody!! This weird-o just bought a peppermint-flavored, striped, lubricated, colored, libbed lubber!!!'


Now the question is how can I let the clerk in the shop memorize what the player choose.  But as you know we can say different word.
This also happens when Larry are calling on sex-line on the phone. And he is asked a question which player can choose whatever he wants.
 
I really want to know the code for this.  But I have tried. And this is what I have done so far for the phone sex-line code. I don't work very well but this is a least a good start right?  But I don't know what else I can do next when the phone rings back and when it has memorized what the player typed.

Code: Adventure Game Studio
  1. String Phonenumber = Game.InputBox ("Enter a phonenumber:");
  2. if (Phonenumber.CompareTo("5556969" ) == 0) {
  3. Display("'Hello, you have reached the National Hot Line Sex Survey. Please answer the following questions. There may be a wonderful prize waiting for you!!'");  
  4. Display("'What is the name of your favourite sex partner?'");
  5. }
  6. String Phonenumber1 = Game.InputBox ("");
  7. if (Phonenumber1.CompareTo("" ) == 0) {
  8. Display("'What is the best part of your partner's anatomy?'");
  9. }
  10. String Phonenumber2 = Game.InputBox ("");
  11. if (Phonenumber1.CompareTo("" ) == 1) {
  12. Display("'What do the two of you like to do together?'");
  13. }
  14. String Phonenumber3 = Game.InputBox ("");
  15. if (Phonenumber3.CompareTo("" ) == 2) {
  16. Display("'What is the best part of your body?'");
  17. }
  18. String Phonenumber4 = Game.InputBox ("");
  19. if (Phonenumber4.CompareTo("" ) == 3) {
  20.   Display("'And, finally, name your partner's favorite object.'");
  21. }
  22.  String Phonenumber5 = Game.InputBox ("");
  23.  if (Phonenumber5.CompareTo("" ) == 4) {
  24.  Display("'Thanks for participating. Your prize is...'");
  25.  Display("");
  26.  Display("Hum. Looks like they hung up on you. Oh well. It was probably a bummer prize anyway!");
  27.  }
  28.  String Phonenumber6 = Game.InputBox ("Enter a phonenumber:");
  29.  if (Phonenumber6.CompareTo("2096836858" ) == 0) {
  30.  Display("'Hello. a pleasant voice responds. 'Sierra On-Line.'");
  31.  Display("'We're not open right now, but if you'd call during business hours (and stip using this pretend telephone), we would be happy to sell you a 'Leisure suit Larry Hint Book.''");
  32.  Display("'Written by Al Lowe, the author of Leisure Suit Larry, you know it at least tries to be humorous. The answers are invisible, until you mark them with the special pen provided, so you never have to worry about inadvertently learning something you didn't want to know.'");
  33.  Display("'Thank you for calling Sierra On-Line, and for your purchase of 'Leisure Suit Larry in the Land of the Lounge Lizards.' Good bye.'");
  34.  Display("Such blatant commercialism turns you on. You make a mental note to purchase on of those great, Al Lowe Hint Books!");
  35.  }
  36. }
  37.  
 
« Last Edit: 16 Jun 2017, 11:45 by Fribbi »

Khris

    • Lifetime Achievement Award Winner
    •  
    • I can help with play testing
    •  
    • I can help with scripting
    •  
    • I can help with translating
    •  
  • Khris worked on a game that was nominated for an AGS Award!
How are you getting player input? Only by typing into an input box?
What if the player types something other than the two options?

Anyway, here's example code.
Code: Adventure Game Studio
  1. String Ask(String question, String option1, String option2) {
  2.   String input;
  3.   while (true) {
  4.     input = Game.InputBox(question);
  5.     if (input.CompareTo(option1) == 0) return option1;
  6.     if (input.CompareTo(option2) == 0) return option2;
  7.   }
  8. }
  9.  
  10. // to use this:
  11.   String clerk = "";
  12.   String texture = Ask("What kind of lubber you want? Smooth or libbed?", "smooth", "libbed");
  13.   ...
  14.   clerk = String.Format("Hey, everybody!! This weird-o just bought a %s, %s, %s lubber!", texture, ...);  // insert choices
  15.   Display(clerk);

Snarky

  • Global Moderator
  • Mittens Earl
  • Private Insultant
    • I can help with proof reading
    •  
    • I can help with translating
    •  
If you're using text controls throughout the game, you should really look into the Parser API. It is very simple (even primitive), but it saves you from some of this work (in particular, it is useful if you want to treat a whole bunch of words as synonyms).

Apart from that, Khris already gave you the answer. Just save what the player said as a String variable, and use String.Format to insert it into later statements.

Thank you. :-D

Thanks again Khris.
I have now a another question.
How can I let the clerk repeat the same words I have already chosen again when I go out and visit the shop again.


I used that code in a global script.

Code: Adventure Game Studio
  1. String Ask(String question, String option1, String option2) {
  2.   String input;
  3.   while (true) {
  4.     input = Game.InputBox(question);
  5.     if (input.CompareTo(option1) == 0) return option1;
  6.     if (input.CompareTo(option2) == 0) return option2;
  7.   }
  8. }

And this when I talk to clerk.

Code: Adventure Game Studio
  1. String clerk = "";
  2.   String texture = Ask("What kind of lubber you want? Smooth or libbed?", "smooth", "libbed");
  3.   ...
  4.   clerk = String.Format("Hey, everybody!! This weird-o just bought a %s, %s, %s lubber!", texture, ...);  // insert choices
  5.   Display(clerk);

But when I want to go out I need him to say the same chosen words again.

I have tried this code again when player leaves room but it wont work. 

So what am I doing wrong?

Code: Adventure Game Studio
  1.  clerk = String.Format("Hey, Meester!!' yells the clerk. 'I hope you enjoy your %s-flavoerd a %s, %s, %s, %s lubber!", texture5,texture4,texture3,texture2, texture1);  // insert choices
  2.   Display(clerk);





« Last Edit: 17 Jun 2017, 17:04 by Fribbi »

Mandle

  • NO PIXEL LEFT BEHIND!!!
  • Mandle worked on a game that was nominated for an AGS Award!
So what am I doing wrong?

Code: Adventure Game Studio
  1.  clerk = String.Format("Hey, Meester!!' yells the clerk. 'I hope you enjoy your %s-flavoerd a %s, %s, %s lubber!", texture5,texture4,texture3,texture2, texture1);  // insert choices
  2.   Display(clerk);

You have four %s but you have five "texture" variables.

oops. I have fixed that.

But I still have a problem with this.

Snarky

  • Global Moderator
  • Mittens Earl
  • Private Insultant
    • I can help with proof reading
    •  
    • I can help with translating
    •  
Which is... ?

Like I said. I can't let the clerk repeat the same words I had chosen when I leave room.

Quote
clerk = String.Format("Hey, Meester!!' yells the clerk. 'I hope you enjoy your %s-flavoerd a %s, %s, %s, %s lubber!", texture5,texture4,texture3,texture2, texture1);  // insert choices
  Display(clerk);

Do I have to add this code again to get it to work?  I thought it was enough if I put this on the Main global script.

Code: Adventure Game Studio
  1. String Ask(String question, String option1, String option2) {
  2.   String input;
  3.   while (true) {
  4.     input = Game.InputBox(question);
  5.     if (input.CompareTo(option1) == 0) return option1;
  6.     if (input.CompareTo(option2) == 0) return option2;
  7.   }
  8. }
  9.  


And what code do I use if I wan the player to say whatever he wants to write and without options? You know when Leisure suit Larry phones to sex-line he could chose any kind of words and when he leaves the room screen and came back to same room screen the phone will suddenly ring and when Larry pick up the phone the woman in the phone says the same words what the player wrote. 

And lastly how do I make a custom GUI inputbox to work?


I'm sorry if my English is terrible for you to understand. But I hope you understood what I am asking for.

 
« Last Edit: 17 Jun 2017, 19:47 by Fribbi »

Snarky

  • Global Moderator
  • Mittens Earl
  • Private Insultant
    • I can help with proof reading
    •  
    • I can help with translating
    •  
Like I said. I can't let the clerk repeat the same words I had chosen when I leave room.

Quote
clerk = String.Format("Hey, Meester!!' yells the clerk. 'I hope you enjoy your %s-flavoerd a %s, %s, %s, %s lubber!", texture5,texture4,texture3,texture2, texture1);  // insert choices
  Display(clerk);

And it doesn't work HOW? What happens when your game gets to that point? If it won't compile, or if it crashes, what does the error message say? "It doesn't work" is not a helpful bug description.

Looking at all your different code snippets, my first guess is that all your texture1-5 variables are local within the function, rather than global (defined outside of any function). Variables that are defined inside a function disappear once you exit the function. If you want them to stick around, you have to define them globally.

Quote
And what code do I use if I wan the player to say whatever he wants to write and without options? You know when Leisure suit Larry phones to sex-line he could chose any kind of words and when he leaves the room screen and came back to same room screen the phone will suddenly ring and when Larry pick up the phone the woman in the phone says the same words what the player wrote.

You use a TextBox. In the editor for the GUI, in the TextBox's event pane, click to create an event handler for when the user presses enter (OnActivate). In that function, read the TextBox's .Text property and store it in a String variable, as before.

Quote
And lastly how do I make a custom GUI inputbox to work?

You follow the instructions in the manual.
« Last Edit: 17 Jun 2017, 20:41 by Snarky »

Quote
Looking at all your different code snippets, my first guess is that all your texture1-5 variables are local within the function, rather than global (defined outside of any function). Variables that are defined inside a function disappear once you exit the function. If you want them to stick around, you have to define them globally.

Ok I understand. 

Khris

    • Lifetime Achievement Award Winner
    •  
    • I can help with play testing
    •  
    • I can help with scripting
    •  
    • I can help with translating
    •  
  • Khris worked on a game that was nominated for an AGS Award!
I would also urge you not to name them textureX but condomTexture, condomColor, condomTaste, etc, especially now that they're going to be global variables.

monkey0506

  • AGS Project Tracker Admins
  • Tasting the banhammer. Strangely, tastes like ham.
And it doesn't work HOW? What happens when your game gets to that point? If it won't compile, or if it crashes, what does the error message say? "It doesn't work" is not a helpful bug description.

Ok I understand.

I lol'd.
User was banned for this post.