Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Joe on Mon 11/09/2006 17:48:40

Title: How can I select all characters?
Post by: Joe on Mon 11/09/2006 17:48:40
Hello.

I've been thinking about this possibility long time ago.
Wouldnt you be able to do something like this:

e.g.:
AllCharacters.FollowCharacter(cEgo,5,0);

It would make all characters in the room except the player, do the action, in that case: Follow EGO.
Title: Re: SUGGESTION: AllCharacters
Post by: SSH on Mon 11/09/2006 17:51:43
Or..


int i=0;
while (i<Game.CharacterCount) {
  if (i!=player.ID && character[i].Room==player.Room) {
    character[i].FollowCharacter(player,5,0);
  }
  i++;
}


or be really cunning...

#define AllCharacters int i=0;while (i<Game.CharacterCount) { if (i!=player.ID && character[i].Room==player.Room) character[i]
#define ACEnd i++;}

AllCharacters.FollowCharacter(player,5,0); ACEnd


...which might not work!
Title: Re: SUGGESTION: AllCharacters
Post by: Ashen on Mon 11/09/2006 17:59:17
Suggestions belong in the Technical Forum. The reason your previous one got bumped over here is, it's pretty much dealt with by an existing function.

If SSH's workaround is no good for you, or you want to go ahead with the suggestion anyway, I'll move the thread over. However, I can't see the suggestion getting much support, when it's so easy to code, and might cause more problems than it solves (e.g. would it actually be ALL characters, or all characters in the current room? Would it include the palyer character? What about any NPCs used in the following code, like the FollowCharacter command?). As with the other thread, you really should try asking how something can be achieved, before jumping to a suggestion.

EDIT:
And I don't think that second version will work, SSH. Don't #define'd values have to be constant?
Title: Re: How can I select all characters?
Post by: Joe on Mon 11/09/2006 18:05:04
Sorry then, I never guess right
Thanks SSH, Ashen.

When I said AllCharcters I meant All Characters in the room except the player
Title: Re: How can I select all characters?
Post by: SSH on Mon 11/09/2006 18:08:09
#defines just do a textual substitution. The reason it might not work is if the substitution stops at the first space. I use this myself:


function Go(int x, int y) {
  //Display("Go! %d %d", x, y);
  player.Walk(x, y, eNoBlock, eWalkableAreas);
  Wait(15);
  while (player.Moving) {
    if (Mouse.IsButtonDown(eMouseLeft)) {
      player.StopMoving();
      return -1;
    }
    Wait(1);
  }
  return 0;
}
#define GO if(Go
#define OR_ABORT )return

...

GO(oBread.X, oBread.Y)OR_ABORT;
oBread.Visible=0;
player.AddInventory(iBread);



which gives you an abortable walk, when within an interaction function...
Title: Re: SUGGESTION: AllCharacters
Post by: monkey0506 on Mon 11/09/2006 19:09:53
Now this is just ridiculous....

managed struct AllCharacters {
  #ifndef SCR_NO_VALUE // I'm not sure if this #define persists into user scripts
  #define SCR_NO_VALUE 31998 // also I did no testing of any of this code
  #endif
  import static void AddInventory(InventoryItem *item, int addAtIndex=SCR_NO_VALUE);
  import static void Animate(int loop, int delay, RepeatStyle=eOnce, BlockingStyle=eBlock, Direction=eForwards);
  import static void ChangeRoom(int room, int x=SCR_NO_VALUE, int y=SCR_NO_VALUE);
  import static void ChangeView(int view);
  import static void FaceCharacter(Character* , BlockingStyle=eBlock);
  import static void FaceLocation(int x, int y, BlockingStyle=eBlock);
  import static void FaceObject(Object* , BlockingStyle=eBlock);
  import static void FollowCharacter(Character*, int dist=10, int eagerness=97);
  import static void LockView(int view);
  import static void LockViewAligned(int view, int loop, Alignment);
  import static void LockViewFrame(int view, int loop, int frame);
  import static void LockViewOffset(int view, int xOffset, int yOffset);
  import static void LoseInventory(InventoryItem *item);
  import static void PlaceOnWalkableArea();
  import static void RemoveTint();
  import static void RunInteraction(CursorMode);
  import static void SetIdleView(int view, int delay);
  import static void SetWalkSpeed(int x, int y);
  import static void StopMoving();
  import static void Tint(int red, int green, int blue, int saturation, int luminance);
  import static void UnlockView();
  import static void Walk(int x, int y, BlockingStyle=eNoBlock, WalkWhere=eWalkableAreas);
  import static void WalkStraight(int x, int y, BlockingStyle=eNoBlock);
  import static void SetActiveInventory(InventoryItem* ActiveInventory);
  import static void SetAnimationSpeed(int AnimationSpeed);
  import static void SetBaseline(int  Baseline);
  import static void SetBlinkInterval(int  BlinkInterval);
  import static void SetBlinkView(int BlinkView);
  import static void SetBlinkWhileThinking(bool BlinkWhileThinking);
  import static void SetBlockingHeight(int BlockingHeight);
  import static void SetBlockingWidth(int BlockingWidth);
  import static void SetClickable(bool Clickable);
  import static void SetDiagonalLoops(bool DiagonalLoops);
  import static void SetFrame(int Frame);
  import static void SetIgnoreLighting(bool IgnoreLighting);
  import static void SetIgnoreWalkbehinds(bool IgnoreWalkbehinds);
  import static void SetInventoryQuantity(InventoryItem* item, int quantity);
  import static void SetLoop(int Loop);
  import static void SetManualScaling(bool ManualScaling);
  import static void SetScaleMoveSpeed(bool ScaleMoveSpeed);
  import static void SetScaleVolume(bool ScaleVolume);
  import static void SetScaling(int Scaling);
  import static void SetSolid(bool Solid);
  import static void SetSpeechColor(int SpeechColor);
  import static void SetSpeechView(int SpeechView);
  import static void SetThinkView(int ThinkView);
  import static void SetTransparency(int Transparency);
  import static void SetTurnBeforeWalking(bool TurnBeforeWalking);
  import static void SetX(int x);
  import static void SetY(int y);
  import static void SetZ(int z);
  import static void SetVisible(bool Visible);
  };

static void AllCharacters::AddInventory(InventoryItem *item, int addAtIndex) {
  int i = 0;
  while (i < Game.CharacterCount) {
    character[i].AddInventory(item, addAtIndex);
    i++;
    }

static void AllCharacters::Animate(int loop, int delay, RepeatStyle repeat, BlockingStyle block, Direction direction) {
  int i = 0;
  while (i < Game.CharacterCount) {
    if (character[i].Room == player.Room) character[i].Animate(loop, delay, repeat, block, direction);
    i++;
    }
  }

static void AllCharacters::ChangeRoom(int room, int x, int y) {
  int i = 0;
  while (i < Game.CharacterCount) {
    character[i].ChangeRoom(room, x, y);
    i++;
    }
  }

static void AllCharacters::ChangeView(int view) {
  int i = 0;
  while (i < Game.CharacterCount) {
    character[i].ChangeView(view);
    i++;
    }
  }

static void AllCharacters::FaceCharacter(Character* Char, BlockingStyle block) {
  if ((Char == null) || (Char.Room != player.Room)) return;
  int i = 0;
  while (i < Game.CharacterCount) {
    if ((character[i].Room == player.Room) && (character[i] != Char)) character[i].FaceCharacter(Char, block);
    i++;
    }
  }

static void AllCharacters::FaceLocation(int x, int y, BlockingStyle block) {
  int i = 0;
  while (i < Game.CharacterCount) {
    if (character[i].Room == player.Room) character[i].FaceLocation(x, y, block);
    i++;
    }
  }

static void AllCharacters::FaceObject(Object* obj, BlockingStyle block) {
  int i = 0;
  while (i < Game.CharacterCount) {
    if (character[i].Room == player.Room) character[i].FaceObject(obj, block);
    i++;
    }
  }

static void AllCharacters::FollowCharacter(Character* Char, int dist, int eagerness) {
  if ((Char == null) || (Char.Room != player.Room)) return;
  int i = 0;
  while (i < Game.CharacterCount) {
    if ((character[i].Room == player.Room) && (character[i] != Char)) character[i].FollowCharacter(Char, dist, eagerness);
    i++;
    }
  }

static void AllCharacters::LockView(int view) {
  int i = 0;
  while (i < Game.CharacterCount) {
    character[i].LockView(view);
    i++;
    }
  }

static void AllCharacters::LockViewAligned(int view, int loop, Alignment align) {
  int i = 0;
  while (i < Game.CharacterCount) {
    character[i].LockViewAligned(view, loop, align);
    i++;
    }
  }

static void AllCharacters::LockViewFrame(int view, int loop, int frame) {
  int i = 0;
  while (i < Game.CharacterCount) {
    character[i].LockViewFrame(view, loop, frame);
    i++;
    }
  }

static void AllCharacters::LockViewOffset(int view, int xOffset, int yOffset) {
  int i = 0;
  while (i < Game.CharacterCount) {
    character[i].LockViewOffset(view, xOffset, yOffset);
    i++;
    }
  }

static void AllCharacters::LoseInventory(InventoryItem *item) {
  int i = 0;
  while (i < Game.CharacterCount) {
    character[i].LoseInventory(item);
    i++;
    }
  }

static void AllCharacters::PlaceOnWalkableArea() {
  int i = 0;
  while (i < Game.CharacterCount) {
    character[i].PlaceOnWalkableArea();
    i++;
    }
  }

static void AllCharacters::RemoveTint() {
  int i = 0;
  while (i < Game.CharacterCount) {
    character[i].RemoveTint();
    i++;
    }
  }

static void AllCharacters::RunInteraction(CursorMode mode) {
  int i = 0;
  while (i < Game.CharacterCount) {
    character[i].RunInteraction(mode);
    i++;
    }
  }

static void AllCharacters::SetIdleView(int view, int delay) {
  int i = 0;
  while (i < Game.CharacterCount) {
    character[i].SetIdleView(view, delay);
    i++;
    }
  }

static void AllCharacters::SetWalkSpeed(int x, int y) {
  int i = 0;
  while (i < Game.CharacterCount) {
    character[i].SetWalkSpeed(x, y);
    i++;
    }
  }

static void AllCharacters::StopMoving() {
  int i = 0;
  while (i < Game.CharacterCount) {
    character[i].StopMoving();
    i++;
    }
  }

static void AllCharacters::Tint(int red, int green, int blue, int saturation, int luminance) {
  int i = 0;
  while (i < Game.CharacterCount) {
    character[i].Tint(red, green, blue, saturation, luminance);
    i++;
    }
  }

static void AllCharacters::UnlockView() {
  int i = 0;
  while (i < Game.CharacterCount) {
    character[i].UnlockView();
    i++;
    }
  }

static void AllCharacters::Walk(int x, int y, BlockingStyle block, WalkWhere where) {
  int i = 0;
  while (i < Game.CharacterCount) {
    character[i].Walk(x, y, block, where);
    i++;
    }
  }

static void AllCharacters::WalkStraight(int x, int y, BlockingStyle block) {
  int i = 0;
  while (i < Game.CharacterCount) {
    character[i].WalkStraight(x, y, block);
    i++;
    }
  }

static void AllCharacters::SetActiveInventory(InventoryItem* ActiveInventory) {
  int i = 0;
  while (i < Game.CharacterCount) {
    character[i].ActiveInventory = ActiveInventory;
    i++;
    }
  }

static void AllCharacters::SetAnimationSpeed(int AnimationSpeed) {
  int i = 0;
  while (i < Game.CharacterCount) {
    character[i].AnimationSpeed = AnimationSpeed;
    i++;
    }
  }

static void AllCharacters::SetBaseline(int  Baseline) {
  int i = 0;
  while (i < Game.CharacterCount) {
    character[i].Baseline = Baseline;
    i++;
    }
  }

static void AllCharacters::SetBlinkInterval(int  BlinkInterval) {
  int i = 0;
  while (i < Game.CharacterCount) {
    character[i].BlinkInterval = BlinkInterval;
    i++;
    }
  }

static void AllCharacters::SetBlinkView(int BlinkView) {
  int i = 0;
  while (i < Game.CharacterCount) {
    character[i].BlinkView = BlinkView;
    i++;
    }
  }

static void AllCharacters::SetBlinkWhileThinking(bool BlinkWhileThinking) {
  int i = 0;
  while (i < Game.CharacterCount) {
    character[i].BlinkWhileThinking = BlinkWhileThinking;
    i++;
    }
  }

static void AllCharacters::SetBlockingHeight(int BlockingHeight) {
  int i = 0;
  while (i < Game.CharacterCount) {
    character[i].BlockingHeight = BlockingHeight;
    i++;
    }
  }

static void AllCharacters::SetBlockingWidth(int BlockingWidth) {
  int i = 0;
  while (i < Game.CharacterCount) {
    character[i].BlockingWidth = BlockingWidth;
    i++;
    }
  }

static void AllCharacters::SetClickable(bool Clickable) {
  int i = 0;
  while (i < Game.CharacterCount) {
    character[i].Clickable = Clickable;
    i++;
    }
  }

static void AllCharacters::SetDiagonalLoops(bool DiagonalLoops) {
  int i = 0;
  while (i < Game.CharacterCount) {
    character[i].DiagonalLoops = DiagonalLoops;
    i++;
    }
  }

static void AllCharacters::SetFrame(int Frame) {
  int i = 0;
  while (i < Game.CharacterCount) {
    character[i].Frame = Frame;
    i++;
    }
  }

static void AllCharacters::SetIgnoreLighting(bool IgnoreLighting) {
  int i = 0;
  while (i < Game.CharacterCount) {
    character[i].IgnoreLighting = IgnoreLighting;
    i++;
    }
  }

static void AllCharacters::SetIgnoreWalkbehinds(bool IgnoreWalkbehinds) {
  int i = 0;
  while (i < Game.CharacterCount) {
    character[i].IgnoreWalkbehinds = IgnoreWalkbehinds;
    i++;
    }
  }

static void AllCharacters::SetInventoryQuantity(InventoryItem* item, int quantity) {
  if (item == null) return;
  int i = 0;
  while (i < Game.CharacterCount) {
    character[i].InventoryQuantity[item.ID] = quantity;
    i++;
    }
  }

static void AllCharacters::SetLoop(int Loop) {
  int i = 0;
  while (i < Game.CharacterCount) {
    character[i].Loop = Loop;
    i++;
    }
  }

static void AllCharacters::SetManualScaling(bool ManualScaling) {
  int i = 0;
  while (i < Game.CharacterCount) {
    character[i].ManualScaling = ManualScaling;
    i++;
    }
  }

static void AllCharacters::SetScaleMoveSpeed(bool ScaleMoveSpeed) {
  int i = 0;
  while (i < Game.CharacterCount) {
    character[i].ScaleMoveSpeed = ScaleMoveSpeed;
    i++;
    }
  }

static void AllCharacters::SetScaleVolume(bool ScaleVolume) {
  int i = 0;
  while (i < Game.CharacterCount) {
    character[i].ScaleVolume = ScaleVolume;
    i++;
    }
  }

static void AllCharacters::SetScaling(int Scaling) {
  int i = 0;
  while (i < Game.CharacterCount) {
    character[i].Scaling = Scaling;
    i++;
    }
  }

static void AllCharacters::SetSolid(bool Solid) {
  int i = 0;
  while (i < Game.CharacterCount) {
    character[i].Solid = Solid;
    i++;
    }
  }

static void AllCharacters::SetSpeechColor(int SpeechColor) {
  int i = 0;
  while (i < Game.CharacterCount) {
    character[i].SpeechColor = SpeechColor;
    i++;
    }
  }

static void AllCharacters::SetSpeechView(int SpeechView) {
  int i = 0;
  while (i < Game.CharacterCount) {
    character[i].SpeechView = SpeechView;
    i++;
    }
  }

static void AllCharacters::SetThinkView(int ThinkView) {
  int i = 0;
  while (i < Game.CharacterCount) {
    character[i].ThinkView = ThinkView;
    i++;
    }
  }

static void AllCharacters::SetTransparency(int Transparency) {
  int i = 0;
  while (i < Game.CharacterCount) {
    character[i].Transparency = Transparency;
    i++;
    }
  }

static void AllCharacters::SetTurnBeforeWalking(bool TurnBeforeWalking) {
  int i = 0;
  while (i < Game.CharacterCount) {
    character[i].TurnBeforeWalking = TurnBeforeWalking;
    i++;
    }
  }

static void AllCharacters::SetX(int x) {
  int i = 0;
  while (i < Game.CharacterCount) {
    character[i].x = x;
    i++;
    }
  }

static void AllCharacters::SetY(int y) {
  int i = 0;
  while (i < Game.CharacterCount) {
    character[i].y = y;
    i++;
    }
  }

static void AllCharacters::SetZ(int z) {
  int i = 0;
  while (i < Game.CharacterCount) {
    character[i].z = z;
    i++;
    }
  }

static void AllCharacters::SetVisible(bool Visible) {
  int i = 0;
  while (i < Game.CharacterCount) {
    character[i].on = Visible;
    i++;
    }
  }


Well...that was fun.

And no...I won't make a module.

[EDIT:]

BTW...function pointers would be awesome ;)