Object appears if two inventory items have been used (Solved)

Started by HSIAMetalKing, Fri 15/02/2008 21:15:44

Previous topic - Next topic

HSIAMetalKing

This probably has a very simple answer... but I can not for the life of me figure out what to do. >.<

I want an object in my game (a door) to appear after two inventory items (milk and cereal) have been used on an object (bowl).

I understand how to use the two inventory items on the bowl using conditionals, but what I don't know how to do is make the door appear AFTER I've used both of them.

Any help at all would be greatly appreciated.

OneDollar

#1
You'll need to have a variable that counts how many of the items have been used, then makes the door appear when it reaches the correct amount. For example (in AGS 3.0)...
Code: ags

//At the top of the room script
//declare your variable
int breakfast=0;  //stores how many items have been used, initially none


//in the use inventory on bowl function
function oBowl_UseInv()
{
  //first do the interactions
  if(player.ActiveInventory==iMilk){
    //use the milk
    breakfast++;  //used an item so increase breakfast by one
  }else if(player.ActiveInventory==iCereal){
    //use the cereal
    breakfast++;
  }else{
    player.Say("I can't use that");  //used some other item, don't increase variable
  }

  //now check to see if both items have been used
  if(breakfast==2){
    oDoor.Visible=true;  //make the door appear
  }
}


Obviously with this method you'd have to bear in mind that if the player keeps hold of the milk or cereal they'd be able to use them twice to make the door appear. In that case you'd need to use separate booleans for the milk and the cereal, set to true when they're used, and check that they're both true before making the door appear.

Khris

Alternatively, make sure the player can't use the two items again, e.g. by replacing the bottle of milk with an empty bottle after it has been used on the bowl.

Or, while we're at it:
Code: ags
function oBowl_UseInv() {

  if(player.ActiveInventory==iMilk) {
    if (breakfast != 1) breakfast++;
  }
  else if(player.ActiveInventory==iCereal) {
    if (breakfast < 2) breakfast+=2;
  } 
  else player.Say("I can't use that");

  if(breakfast==3) oDoor.Visible=true;  
}


scnr ;)


SMF spam blocked by CleanTalk