Saying something different the SECOND time

Started by DrakeStoel, Thu 19/05/2011 07:03:38

Previous topic - Next topic

DrakeStoel

Hi! This is my first post here, and I'm kinda new at this. I've got this problem. Ya see, I wanna make it so that when my character talks to and object (Because he does that (He's kinda crazy)), he makes a witty remark. Then every time he talks to the object AFTER that, he says something different every time. Anyone's help WOULD be appreciated ;D

Hudders

#1
You need a variable that increments every time he speaks to the object.

EDIT: I tried to provide an example but my brain has failed me and I can't remember the syntax.

Wyz

Code: ags

int talkedToObject = 0;

// Inside the function:
  if (talkedToObject <= 3) // Match this number with the last ==  below if you add more
  {
    if (talkedToObject == 0) player.Say("Something");
    else if (talkedToObject == 1) player.Say("Something else");
    else if (talkedToObject == 2) player.Say("Something different");
    else if (talkedToObject == 3) player.Say("Something else")
    
    talkedToObject++;
  }
  else
  {
    player.Say("Something the same");
    
    // To make it loop add the following line
    talkedToObject = 0;
  }
Life is like an adventure without the pixel hunts.

Khris

Or:

Code: ags
  if (Game.DoOnceOnly("talk to chair1"))
    player.Say("witty remark");
  else
    player.Say("something different");


Game.DoOnceOnly()  <- manual entry

DrakeStoel

I tried both of those methods, but I kept getting "parse error at 'else'. What does that mean? (Like I say, I'm new at this) :-[

TomatoesInTheHead

We need your code to find the error.

Maybe you wrote more than one line after the if statement, and didn't use brackets?

DrakeStoel

Here. This is my code

Code: ags
function oClock_Talk()
{
  if (Game.DoOnceOnly("talk to clock"))
    player.Say("Hey");
    Wait (40);
    player.Say ("Hey you");
    Wait (20);
    player.Say ("Ya you, with the FACE");
  else
    player.Say ("That was funny once");
}

Khris

Right, sorry, my bad.

If you're going to use more than one command after an if or else, you have to encapsulate them in curly brackets:

Code: ags
function oClock_Talk()
{
  if (Game.DoOnceOnly("talk to clock"))
  {
    player.Say("Hey");
    Wait (40);
    player.Say ("Hey you");
    Wait (20);
    player.Say ("Ya you, with the FACE");
  }
  else
    player.Say ("That was funny once");  // <- just one command, no brackets needed
}


I apologize again for the "trap", but you could've solved this on your own.

DrakeStoel

Wow. You're totally right...  :-[
Well, the new code works great. Thanks!

SMF spam blocked by CleanTalk