Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: accidentalrebel on Mon 23/05/2011 02:06:29

Title: How to loop through all characters in a room
Post by: accidentalrebel on Mon 23/05/2011 02:06:29
I want to make all the characters in the room disappear at once. Now I can do this manually by changing the visibility of the characters one but the problem with this is that what if I add a couple of more characters, that means I need to edit and add that new character to the code.

I am looking for a way that can do this automatically. What I have in mind is that the engine loops through all the characters present in the room. For each character that is read, their visibility is toggled.

I hope you guys can help me with this. This would really help in making me understand how AGS works.

Cheers!
Title: Re: How to loop through all characters in a room
Post by: Khris on Mon 23/05/2011 02:13:42
This should work:

 int i;
 while (i < Game.CharacterCount) {
   if (character[i].Room == player.Room) character[i].Transparency = 100;
   i++;
 }


character[] is the global array pointing to all characters.

Edit: right, corrected
Title: Re: How to loop through all characters in a room
Post by: Ryan Timothy B on Mon 23/05/2011 02:24:59
Khris, I believe you meant:
character[i].Transparency = 100;

Since there isn't a Visibility function. Either that or the untested, and prone to errors, character.on = false;
Title: Re: How to loop through all characters in a room
Post by: accidentalrebel on Mon 23/05/2011 02:31:10
Hi guys,

That's exactly what I was looking for. And yes, instead of visibility, transparency can be used!

Thank you for all of your quick responses!
Title: Re: How to loop through all characters in a room
Post by: Snarky on Mon 23/05/2011 08:22:55
I find that even with Transparency = 100, characters still show up in @OVERHOTSPOT@ and respond to mouse clicks. To make them completely invisible to the game, I suggest you also set character.Clickable = false;
Title: Re: How to loop through all characters in a room
Post by: Matti on Mon 23/05/2011 12:30:04
Why not use the ChangeRoom command?
Title: Re: How to loop through all characters in a room
Post by: Hernald on Mon 23/05/2011 13:29:58
Quote from: Matti on Mon 23/05/2011 12:30:04
Why not use the ChangeRoom command?
That could work, but might complicate things if one of the characters was the player, by going straight to the destination room without showing the characters disappear.