Author Topic: How can I let NPC Memorize all words and repeat what player said? (Solved)  (Read 1169 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 Jul 2017, 05:07 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.

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);


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.


Well laugh at me if you want, but I thought I would understood this but I was wrong. You know I'm still trying me best to learn on this. :~(

What I did I added this code you can see bellow when I wanted my player to talk to character. It worked fine!

But this code don't work when I want the clerk to say the same line (Hey, Meester!!' yells the clerk. 'I hope you enjoy your %s-flavoerd a %s, %s, %s, %s lubber!), when I step on a region.

So how do I define these code globally so the message which the clerk needs to says to player will always work when I look, touch, or whatever I will do to him, after I have typed in the input box my choices?

I admit I'm not very good on AGS coding. But I'm trying my best.

I promise I will add your nickname on my game when it is ready as a thanks for great help.:smiley:



« Last Edit: 26 Jun 2017, 19:14 by Fribbi »

I'm still having problem with this.

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.



...and the search continues.

We can't help you if you're not describing what is actually happening and what you want/expect to be happening. (wtf) (wrong)
User was banned for this post.

dayowlron

  • been programming computers since 1981
    • I can help with AGS tutoring
    •  
    • I can help with proof reading
    •  
    • I can help with scripting
    •  
    • I can help with story design
    •  
the only question I see you asking is how to make variables global?
There is a global section in the IDE. Look in the manual other features->Global Variables
Manual: http://www.adventuregamestudio.co.uk/manual/
If there is some other problem you are having please specify what it is.
Pro is the opposite of Con
This fact can clearly be seen,
If progress means to move forward
Then what does congress mean?  --Charles Nipsey Russell

Yes I have finally got this in this time.
And everything works now.  Thanks again.

I only had to remove the "String" after I have added these String in global variables.

instead for using
Code: Adventure Game Studio
  1. String clerk;

I only say
Code: Adventure Game Studio
  1. clerk;
  without writing "String" in the front.




I have finally learnt how to use this global variables now.

Case closed.

Re: Code for Quiz game
« Reply #18 on: 16 Jul 2017, 04:55 »
Now I have another questions.

I'm working on a Quiz game which will be included in my game.

This code works only if I don't write nothing in the parser.

Code: Adventure Game Studio
  1. if (txtParserInput.Text.CompareTo("" ) == 0) {
  2. Display("Whatever man!);
  3.  
  4.  

Yes I know this code works when you say the correct password: Rumplestiltskin

Code: Adventure Game Studio
  1.  if (txtParserInput.Text.CompareTo("Rumplestiltskin" ) == 0) {
  2. Display("Correct!);

But what is the code for, if I want the player answer the question with any words he typed in as an answer?

Remember when Leisure Suit Larry make a phone call to the sex-line?
You could type any word you wanted in the parser and you always got a different reply.

After Larry leaves the screen and comes back the screen and answered the phones
the phones replied to you with the words player typed in the input parser.

I need to know the code for that.

???
« Last Edit: 16 Jul 2017, 05:08 by Fribbi »

Are this questions too difficult for you understand again? Or are many of you in summer vacation? :/

I found this old thread which could maybe help me.
The quiz module file in this thread are again gone. Are any chance if you Chris could upload it again? I would like to try it.

http://www.adventuregamestudio.co.uk/forums/index.php?topic=46049.msg618979#msg618979
« Last Edit: 18 Jul 2017, 07:35 by Fribbi »