Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: PokeyFlame on Wed 30/04/2008 20:39:14

Title: Speech problem
Post by: PokeyFlame on Wed 30/04/2008 20:39:14
I'm pretty certain this script should work as I intend it to work:-
First time speaking to character plays speech dHospital1,
Second and every other time without Global Int 12 set to 1 should play speech dHospital 2,
And finally if Global Int is set to 1 then it should play dHospital3 once then switch back to dHospital2

function cSchoolkid_Talk()
{
  if (GetGlobalInt(10) ==1) {
    player.Walk(278, 89, eBlock);
    player.Walk(277, 89, eBlock);
    dHospital2.Start();
  }
  if (GetGlobalInt(12) ==1) {
    player.Walk(278, 89, eBlock);
    player.Walk(277, 89, eBlock);
    dHospital3.Start();
    player.AddInventory(iCorpseID);
    player.AddInventory(iMetal);
    GiveScore(2);
    SetGlobalInt(12, 2);
SetGlobalInt(10, 1);   
    }
  else {
    player.Walk(278, 89, eBlock);
    player.Walk(277, 89, eBlock);
dHospital1.Start();
SetGlobalInt(10, 1);
SetGlobalInt(11, 1);
}
}

However, after ending dHospital2 it straight away goes to dHospital1, as if it's meant to play both instead of just dHospital2.
I've checked the dialog commands in dHospital2 and there isn't anything that says to change to dHospital1. If anyone understands how to make it stop going straight to dHospital1 after dHospital2 please tell me how to correct it. Thanks.
Title: Re: Speech problem
Post by: Dualnames on Wed 30/04/2008 20:50:10

function cSchoolkid_Talk(){
if ((GetGlobalInt(10)!=1) && (GetGlobalInt(12)!=1)) {
    player.Walk(278, 89, eBlock);
    player.Walk(277, 89, eBlock);
dHospital1.Start();
SetGlobalInt(10, 1);
SetGlobalInt(11, 1);
return;
}
  if (GetGlobalInt(10) ==1) {
    player.Walk(278, 89, eBlock);
    player.Walk(277, 89, eBlock);
    dHospital2.Start();
  }
  if (GetGlobalInt(12) ==1) {
    player.Walk(278, 89, eBlock);
    player.Walk(277, 89, eBlock);
    dHospital3.Start();
    player.AddInventory(iCorpseID);
    player.AddInventory(iMetal);
    GiveScore(2);
    SetGlobalInt(12, 2);
SetGlobalInt(10, 1);   
return;
    }
}


Hopefully that helps.
Title: Re: Speech problem
Post by: Khris on Wed 30/04/2008 20:51:24
If you want three mutually exclusive cases, you have to use "if ... else if ... else".
I'd do:

function cSchoolkid_Talk() {

  player.Walk(277, 89, eBlock);
  player.FaceLocation(276, 89, eBlock);  // make player face left

  if (GetGlobalInt(10)==0) {
    SetGlobalInt(10, 1);
    dHospital1.Start();
  }
  else if (GetGlobalInt(10)==1) {
    dHospital2.Start();
  }
  else {
    player.AddInventory(iCorpseID);
    player.AddInventory(iMetal);
    GiveScore(2);
    SetGlobalInt(10, 1);
    SetGlobalInt(12, 2);
    dHospital3.Start();
  }
}


To play the third dialog, use SetGlobalInt(10, 2);.
Title: Re: Speech problem
Post by: PokeyFlame on Wed 30/04/2008 21:03:47
Thanks very much. I'll try them both.
Title: Re: Speech problem
Post by: Dualnames on Wed 30/04/2008 21:08:41
I think you should try Khris first.. just a hunch but mine works as well. I might have misinterpreted something..
Title: Re: Speech problem
Post by: PokeyFlame on Wed 30/04/2008 21:20:32
Yeah there was one problem with yours (minor) it was that you didn't input SetGlobalInt(11,1) but I changed it and it works fine.
I didn't try Khris's because I didn't understand what he had done so I tried yours first.
I just didn't understand what !=1) means, whats the ! for?
Title: Re: Speech problem
Post by: Dualnames on Wed 30/04/2008 21:25:35
!= it's the opposite of ==

So that means that my line of code checks that the values of both ints aren't 1 and does some functions.Glad i helped. Rather change the topic name to solved rather than add a thumb but that's fine as well. Glad we helped.
Title: Re: Speech problem
Post by: PokeyFlame on Wed 30/04/2008 21:35:03
Thanks alot. I only put the thumbs up so if people search speech problem then they know which ones have been solved by looking at the thumb. Either way it works i suppose but thanks alot anyway