How to loop through all characters in a room

Started by accidentalrebel, Mon 23/05/2011 02:06:29

Previous topic - Next topic

accidentalrebel

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!

Khris

#1
This should work:

Code: ags
  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

Ryan Timothy B

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;

accidentalrebel

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!

Snarky

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;

Matti


Hernald

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.

SMF spam blocked by CleanTalk