Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: ultravoss on Tue 29/01/2008 12:49:23

Title: Having 3 objects interact
Post by: ultravoss on Tue 29/01/2008 12:49:23
Hi folks,

I wonder how I can create the possibility to let the player character interact with 3 or more objects at once. In particular, it is about cooking food after a recipe.

The objective for the player is like "mix sugar and milk in a cup", after he has chosen these from a larger amount of ingredients (which are all objects). When the player chooses the right ingredients and mingles them with the right device, the task should be accomplished.

Which way would you suggest me to do this in AGS? As far as I understand AGS, you usually don't interact with more than 1 object at a time.

Regards, ultravoss
Title: Re: Having 3 objects interact
Post by: Khris on Tue 29/01/2008 13:10:49
You have to do it manually.
First, you have to let the game know if an object is an ingredient or a container.
One way of doing this:
// top of room script

int objType[];   // declare dynamic array

// player enters screen (before fadein)
  objType = new int[Room.ObjectCount];   // init the array

  objType[oMilk.ID] = 1;         // ingredient
  objType[oSugar.ID] = 1;     // ingredient
  ...
  objType[oCup.ID] = 2;   // container


The next step is to use a custom mouse click function to handle clicks on objects:
// room script
function on_mouse_click(MouseButton button) {
  if (button != eMouseLeft) return;
  if (mouse.Mode != eModeInteract) return;
  if (GetLocationType(mouse.x, mouse.y) != eLocationObject) return;
  Object*o = Object.GetAtScreenXY(mouse.x, mouse.y);
  if (!objType[o.ID]) return;

  // if the script has reached this point, the player interacted with either an ingredient
  // or a container
  ClaimEvent();   // prevent AGS from processing the click

  if (objType[o.ID] == 1) {     // interaction with an ingredient
    ...
  }
  if (objType[o.ID] == 2) {     // interaction with a container
    ...
  }
}


The final step: keep an array with a list of clicked ingredients, add o / o.ID to it (depending on whether it's an array of Objects or their index numbers)
or
have the click on the container check the list, react to that, then clear the list.
Title: Re: Having 3 objects interact
Post by: ultravoss on Tue 29/01/2008 15:43:45
Thanks for your advice, KhrisMUC. I will try that.

Regards,
ultravoss
Title: Re: Having 3 objects interact
Post by: thebaddie on Tue 29/01/2008 15:57:38
or you can use variable

if player use sugar with cup then set sugar variable to 1
if player use milk with cup then set milk variable to 1

if both sugar and milk variable are set to 1... there you go ;)