Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: steptoe on Sat 14/04/2012 12:49:47

Title: NPC's selected to go to next room. Show selected NPC's and their text displays.
Post by: steptoe on Sat 14/04/2012 12:49:47
Hi

I need to solve this vital issue and I hope it is understandable.

Selecting one NPC from a few NPC's and then sending the selected NPC to the final room is not a problem if I use  the Variable 'Character' named Muderer.

Eg if Bertie selected:


  Muderer = cBertie;
 cBertie.ChangeRoom(6);


In final room:


  player.Say("You have been arrested, %s", Murderer.Name);
 Murderer.Say("I'm innocent!");


I believe this is correct but correct me if I am wrong.

My issue is when sending two or more NPC's to the final room.

I need to only show the NPC characters that have been selected and display text in the final room relating to the NPC's selected.

Summery:

Say the Player selects NPC 1 AND 4.  NPC 1 and 4 show in final room. All text is based on NPC 1 and 4 in final room. (selections are done by button for each NPC);

There are 6 NPC's.

Help appreciated.

steptoe



Title: Re: NPC's selected to go to next room. Show selected NPC's and their text displays.
Post by: steptoe on Sat 14/04/2012 16:02:26
Mods: I have double posted so I can show all the code I have used separately.

The below seems to work ok but if you know a better way...

Example of when an NPC 'Arrest' button is clicked:


function Button28_OnClick(GUIControl *control, MouseButton button)
{
Button28.Text="Arrested!";
Murderer=cHarrington;
}


After making Arrest(s) by clicking NPC 'Arrest button' and clicking 'Take to court' button:


function Button34_OnClick(GUIControl *control, MouseButton button)
{
  gArrest.Visible=false;
  cFrankj.ChangeRoom(6);
 
  if (Murderer)
  {
    cHarrington.ChangeRoom(6, 198, 288);
  }
 
 if (Murdererdud)
  {
  cDudley.ChangeRoom(6, 180, 288);
  }
 
 if (Murdererfitz)
  {
  cFitzroy.ChangeRoom(6, 160, 288);
  }
 
 if (MurdererBert)
  {
   cBertie.ChangeRoom(6, 140, 288);
  }
 
 if (MurdererPat)
  {
   cPatrick.ChangeRoom(6, 120, 288);
  }
 
 if (MurdererAnna)
  {
   cAnna.ChangeRoom(6, 100, 288);
  }
  }


And called in Final Room:


function room_AfterFadeIn()
{
if (Murderer)
{
Display("%s you have been found guilty of murder!!",Murderer.Name);
}
if (Murdererdud)
{
Display("%s you have been found guilty of murder!!",Murdererdud.Name);
}
if (Murdererfitz)
{
Display("%s you have been found guilty of murder!!",Murdererfitz.Name);
}
if (MurdererBert)
{
Display("%s you have been found guilty of murder!!",MurdererBert.Name);
}
if (MurdererPat)
{
Display("%s you have been found guilty of murder!!",MurdererPat.Name);
}
if (MurdererAnna)
{
Display("%s you have been found guilty of murder!!",MurdererAnna.Name);
}
}



steptoe



Title: Re: NPC's selected to go to next room. Show selected NPC's and their text displays.
Post by: Khris on Sat 14/04/2012 20:00:07
Sorry, I'm not clear what you're looking for here.

In the final room, this should suffice:

function room_AfterFadeIn() {
  int i = 0;
  while (i < Game.CharacterCount) {
    if (character[i] != player && character[i].Room == player.Room)
      Display("%s, you have been found guilty of murder!!", character[i].Name);
    i++;
  }
}


This code iterates through every character in the game, and for each one, if they are an NPC and in the current room, displays the message.
Title: Re: NPC's selected to go to next room. Show selected NPC's and their text displays.
Post by: steptoe on Sat 14/04/2012 20:02:06
Cheers Khris

I'll give that a go. Certainly less code  ;)

cheers

steptoe

Edit: Khris, it works but gives a small problem. I will see if I can work around it.

cheers

steptoe