How can I let NPC Memorize all words and repeat what player said? (Solved)

Started by Meystari F, Tue 13/06/2017 08:20:22

Previous topic - Next topic

Meystari F

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: ags
String Phonenumber = Game.InputBox ("Enter a phonenumber:");
if (Phonenumber.CompareTo("5556969" ) == 0) {
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!!'");  
Display("'What is the name of your favourite sex partner?'");
}
String Phonenumber1 = Game.InputBox ("");
if (Phonenumber1.CompareTo("" ) == 0) {
Display("'What is the best part of your partner's anatomy?'");
}
String Phonenumber2 = Game.InputBox ("");
if (Phonenumber1.CompareTo("" ) == 1) {
Display("'What do the two of you like to do together?'");
}
String Phonenumber3 = Game.InputBox ("");
if (Phonenumber3.CompareTo("" ) == 2) {
Display("'What is the best part of your body?'");
}
String Phonenumber4 = Game.InputBox ("");
if (Phonenumber4.CompareTo("" ) == 3) {
  Display("'And, finally, name your partner's favorite object.'");
}
 String Phonenumber5 = Game.InputBox ("");
 if (Phonenumber5.CompareTo("" ) == 4) { 
 Display("'Thanks for participating. Your prize is...'");
 Display("");
 Display("Hum. Looks like they hung up on you. Oh well. It was probably a bummer prize anyway!");
 }
 String Phonenumber6 = Game.InputBox ("Enter a phonenumber:");
 if (Phonenumber6.CompareTo("2096836858" ) == 0) {
 Display("'Hello. a pleasant voice responds. 'Sierra On-Line.'");
 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.''");
 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.'");
 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.'");
 Display("Such blatant commercialism turns you on. You make a mental note to purchase on of those great, Al Lowe Hint Books!");
 }
}

 

Khris

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: ags
String Ask(String question, String option1, String option2) {
  String input;
  while (true) {
    input = Game.InputBox(question);
    if (input.CompareTo(option1) == 0) return option1;
    if (input.CompareTo(option2) == 0) return option2;
  }
}

// to use this:
  String clerk = "";
  String texture = Ask("What kind of lubber you want? Smooth or libbed?", "smooth", "libbed");
  ...
  clerk = String.Format("Hey, everybody!! This weird-o just bought a %s, %s, %s lubber!", texture, ...);  // insert choices
  Display(clerk);

Snarky

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.


Meystari F

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: ags
String Ask(String question, String option1, String option2) {
  String input;
  while (true) {
    input = Game.InputBox(question);
    if (input.CompareTo(option1) == 0) return option1;
    if (input.CompareTo(option2) == 0) return option2;
  }
}


And this when I talk to clerk.

Code: ags
String clerk = "";
  String texture = Ask("What kind of lubber you want? Smooth or libbed?", "smooth", "libbed");
  ...
  clerk = String.Format("Hey, everybody!! This weird-o just bought a %s, %s, %s lubber!", texture, ...);  // insert choices
  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: ags
 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);







Mandle

Quote from: Fribbi on Sat 17/06/2017 14:56:09
So what am I doing wrong?

Code: ags
 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
  Display(clerk);


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

Meystari F

oops. I have fixed that.

But I still have a problem with this.

Snarky


Meystari F

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

Quoteclerk = 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: ags
String Ask(String question, String option1, String option2) {
  String input;
  while (true) {
    input = Game.InputBox(question);
    if (input.CompareTo(option1) == 0) return option1;
    if (input.CompareTo(option2) == 0) return option2;
  }
}


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.

 

Snarky

Quote from: Fribbi on Sat 17/06/2017 19:45:16
Like I said. I can't let the clerk repeat the same words I had chosen when I leave room.

Quoteclerk = 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.

QuoteAnd 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.

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

You follow the instructions in the manual.

Meystari F

QuoteLooking 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

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

Quote from: Snarky on Sat 17/06/2017 20:37:24And 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.

Quote from: Fribbi on Sun 18/06/2017 15:16:32Ok I understand.

I lol'd.

Meystari F

Quote from: Fribbi on Sat 17/06/2017 14:56:09
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: ags
String Ask(String question, String option1, String option2) {
  String input;
  while (true) {
    input = Game.InputBox(question);
    if (input.CompareTo(option1) == 0) return option1;
    if (input.CompareTo(option2) == 0) return option2;
  }
}


And this when I talk to clerk.

Code: ags
String clerk = "";
  String texture = Ask("What kind of lubber you want? Smooth or libbed?", "smooth", "libbed");
  ...
  clerk = String.Format("Hey, everybody!! This weird-o just bought a %s, %s, %s lubber!", texture, ...);  // insert choices
  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: ags
 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);



QuoteLooking 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:





monkey0506

Quote from: Snarky on Sat 17/06/2017 20:37:24And 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)

dayowlron

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                       Kids of today are so much different
This fact can clearly be seen,                  Don't you know?
If progress means to move forward         Just ask them where they are from
Then what does congress mean?             And they tell you where you can go.  --Nipsey Russell

Meystari F

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: ags
String clerk;


I only say
Code: ags
clerk;
  without writing "String" in the front.




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

Case closed.

Meystari F

#18
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: ags
if (txtParserInput.Text.CompareTo("" ) == 0) {
Display("Whatever man!);



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

Code: ags
 if (txtParserInput.Text.CompareTo("Rumplestiltskin" ) == 0) {
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.

???

Meystari F

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

SMF spam blocked by CleanTalk