"type topics" -Type of dialog script problem (use of else command)

Started by Thiscold, Fri 15/01/2010 01:57:47

Previous topic - Next topic

Thiscold

Hello all, I'm new to this forum and still learnin the tricks with ags (though densmings tutorial videos were a great help!)

I had problems concerning certain scripts; My goal was to create a dialog that was similiar to the type that leisure suite larry's had. In this type of dialog player types the topics he wants to discuss with an npc into the text gui box and depending on what was typed into the box the npc answered differently etc.


Here's piece of my script (I have to repeat my self that I'm very unexperienced with scripting and I apologise for the confusing names of variables such as playerName while it has nothing to do with playername):
 
function bOk_OnClick(GUIControl *control, MouseButton button)
{
     playerName = tbName.Text; 
     gName.Visible = false;

  {   if (playerName == "merchandise") { {
       cVasta.Say("SHHHSSH! Not so loud! You dont know who is listening");
       cVasta.Say("Thats right the merchandise, so what you into? Vanilla or chocolate ice cream?");
     gName.Visible = true;}
          
          // my goal is to make this word chocolate to not mean anything to the npc until he has asked       about the "merchandise"
           if (playerName == "chocolate")   { 
           cVasta.Say("Oh we got a gentleman with a great taste here");
           cVasta.Say("There you go my good fellow"); 
           }
           }
         
  if (playerName == "yes") {
      cVasta.Say("Yup, thats some heavy stuff I got here for you");
      cVasta.Say("so.. The big question is, which do you like better; chocolate or vanilla ice cream?");
      cVasta.Say("'Couse I got plenty of both");
     }

  else cVasta.Say("Hey man, I'm here only to sell my merchandise");
  }
}

My main problem is this, when the npc (cVasta) has said that sentence "thats right the merchandise, so what you into vanilla or chocolate" and the text box appears (gName) for the player to type his next word to, our npc suddenly executes this command:   "else cVasta.Say("Hey man, I'm here only to sell my merchandise");"

My intention was to have that sentence said only when player typing some word that has no meanin to the npc, so to say. Sorry about long post and I hope someone understood atleast something from my very confusing post and can advice me whats wrong with the current script! Thank you in advance,


Khris

I cleaned up the indentations to understand how AGS processes the current code.

Code: ags
function bOk_OnClick(GUIControl *control, MouseButton button) {
  playerName = tbName.Text; 
  gName.Visible = false;

  {
    if (playerName == "merchandise") {
      {
        cVasta.Say("SHHHSSH! Not so loud! You dont know who is listening");
        cVasta.Say("Thats right the merchandise, so what you into? Vanilla or chocolate ice cream?");
        gName.Visible = true;
      }
          
      // my goal is to make this word chocolate to not mean anything to the npc until he has asked about the "merchandise"
      if (playerName == "chocolate") { 
        cVasta.Say("Oh we got a gentleman with a great taste here");
        cVasta.Say("There you go my good fellow"); 
      }
    }
         
    if (playerName == "yes") {
      cVasta.Say("Yup, thats some heavy stuff I got here for you");
      cVasta.Say("so.. The big question is, which do you like better; chocolate or vanilla ice cream?");
      cVasta.Say("'Couse I got plenty of both");
    }
  
    else cVasta.Say("Hey man, I'm here only to sell my merchandise");
  }
}


There are superfluous {}s in there.
After the player typed "merchandise", the commands in the first if-block are called, then AGS checks whether playername == "yes", and since it isn't, the else line at the end is run.

What you need to do is use a variable:

Code: ags
bool player_typed_merchandise; // initially, this is false

function bOk_OnClick(GUIControl *control, MouseButton button) {
  playerName = tbName.Text; 
  gName.Visible = false;

  if (playerName == "merchandise") {
    cVasta.Say("SHHHSSH! Not so loud! You dont know who is listening");
    cVasta.Say("Thats right the merchandise, so what you into? Vanilla or chocolate ice cream?");
    player_typed_merchandise = true;
  }

  else if (playerName == "chocolate") {
    if (player_typed_merchandise) {
      cVasta.Say("Oh we got a gentleman with a great taste here");
      cVasta.Say("There you go my good fellow"); 
    }
    else {
      cVasta.Say("What are you talking about?");
    }
  }
         
  else if (playerName == "yes") {
    cVasta.Say("Yup, thats some heavy stuff I got here for you");
    cVasta.Say("so.. The big question is, which do you like better; chocolate or vanilla ice cream?");
    cVasta.Say("'Cause I got plenty of both");
  }
  
  else cVasta.Say("Hey man, I'm here only to sell my merchandise");

  gName.Visible = true;
}

Thiscold

Excellent, this works great. Thank you for your assistance. Thanks to you I now understand scripting little bit better!

SMF spam blocked by CleanTalk