Grab all characters in room?

Started by snafu, Fri 04/07/2008 00:50:28

Previous topic - Next topic

snafu

Hi all,

New round here, stumbled across AGS while checking out some of Yahtzee's stuff. Decided to start writing my own game after perusing the manual and these boards for a couple of days. It's coming along quite well and I'm looking for a pointer on how to go about the following:-

I have a spare room in my game which acts as an animation sequence between areas. It's basically a portal in a fantasy like setting. The main character falls down the screen in a Roger Wilco-esque portal sequence. I've got some global variables set up for the destination on the other side of the portal. When the player moves in to the portal room, the animation is triggered and at the end of that, we are warped to the destination room. Sometimes, I need to throw various NPC's in to the portal aswell and have them come out the other side. This is no problem as I've managed to transport 3 characters across to the other side with this method, but it's a tad clunky and I've realised that as the game goes on, the way I'm doing it is going to result in a sack full of "if" statements checking whether certain NPC's should be transported.

So I'm effectively looking to tidy up my code with something that does:
* ~~Grab all characters in room~~
* Changeroom (roomnumber, portal_x, portal_y);


edit: To be a tad more specific just in case,
All relevant characters are transported in to what I'll call the "portal room" and then what I'm after is something to go through each character in that room and run a character.Changeroom on each one in turn, ending with the player.

Cheers

Gilbert

It's not easy to do if people insist on using OO objects for scripting, instead, you may use the character[] array with a while loop to do what you want.

Since you want the player to be the last to change room, assuming that his character id is the 1st (#0) in the game, you may run a while loop by decrementing the numbers, something like (pseudo codes ahead):
Code: ags

int counter = Game.CharacterCount;
while (counter>0){
  counter--;
  if (character[counter].Room== certain room) character[counter].ChangeRoom (blah bla);
}

snafu

That's perfect. Thanks a bundle!

skuttleman

The player won't change room until the function finishes running, the player will be last no matter what.

snafu

Quote from: skuttleman on Fri 04/07/2008 03:11:55
The player won't change room until the function finishes running, the player will be last no matter what.

That's good to know. So I don't need to leave the player's changeroom until the end of the function. Excellent!

SMF spam blocked by CleanTalk