Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Krazy on Tue 25/01/2005 23:11:59

Title: Defualt Inventory Lines [SOLVED]
Post by: Krazy on Tue 25/01/2005 23:11:59
Is there anyway to make the player say a defualt line when I try to use an inventory item with an object/hotspot. E.g when I use say the flower with something that isn't right he'll say "That doens't need any decoration". Or would I have to program it in to say that when the player uses the flower with every other object except the right one  :-X
Title: Re: Defualt Inventory Lines
Post by: Etcher Squared Games on Wed 26/01/2005 00:08:17
check out

unhandled_event

in the manual
Title: Re: Defualt Inventory Lines
Post by: Candle on Wed 26/01/2005 01:01:53
Sorry to butt in here but what would it look like if you want to use unhandled_event (int what, int type)  to say something  if an item is used on something that is not the right one etc .
Title: Re: Defualt Inventory Lines
Post by: Etcher Squared Games on Wed 26/01/2005 01:24:35
unhandled_event (int what, int type)
{

Ã,  if (type == 3)Ã,  // all type 3's are inventory
Ã,  {
Ã,  Ã,  Ã,  if (character[CHARID].activeinv == ITEM_FLOWER)
Ã,  Ã,  Ã,  {
Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  DisplaySpeech (CHARID, "That doesn't need any decoration");
Ã,  Ã,  Ã,  }
Ã,  }
}


Now, if you have a character, object, hotspot, etc that supports inventory click then what you may need to do is a common function on the final else of each inventory click...


On_SOMECHARACTER/ITEM/HOTSPOT/ETC_Inventory_CLICK
{
  if (using the correct item)
  {
      // do the right thing
  }
  else
  {
       DoInvalidItem();
  }
}


function DoInvalidItem()
{

      if (character[CHARID].activeinv == ITEM_FLOWER)
      {
            DisplaySpeech (CHARID, "That doesn't need any decoration");
      }
      else if (character[CHARID].activeinv == ITEM_BOWLINGBALL)
      {
            DisplaySpeech (CHARID, "I can't bowl here.");
      }
}



if there is a better way, "I" would appreciate knowing
Title: Re: Defualt Inventory Lines
Post by: Krazy on Wed 26/01/2005 04:04:42
Ok I put:

function unhandled_event (int what, int type) {
if (type == 3)  // all type 3's are inventory
  {
      if (character[BOB].activeinv == ITEM_FLOWER);
      {
            DisplaySpeech (BOB, "That doesn't need a decoration");
}

But I get a Nested functions not supported error but I seemed to have got the code looking why it's supposed to, I dunno what's going on here.
Title: Re: Defualt Inventory Lines
Post by: Gilbert on Wed 26/01/2005 04:28:54
Coutn the braces, you may also use the "Match Braces" feature of the editor.
If that part of the code you pasted is ALL of that function, you're missing at least 2 closing braces, so function declarations following it would be considered to be within unhandled_event(), also there's an extra semi-colon after an if clause, see:

function unhandled_event (int what, int type) {
Ã,  if (type == 3) // all type 3's are inventory
Ã,  Ã, {
Ã,  Ã, if (character[BOB].activeinv == ITEM_FLOWER) //removed semicolon
Ã, Ã,  Ã, {
Ã,  Ã, Ã,  Ã, DisplaySpeech (BOB, "That doesn't need a decoration");
Ã,  Ã,  }
Ã,  } //Missed this
} //Missed this


You can tidy it up and make it more readible:

function unhandled_event (int what, int type) {
Ã,  if (type == 3) {// all type 3's are inventory
Ã,  Ã,  if (character[BOB].activeinv == ITEM_FLOWER) Ã, Ã,  Ã, DisplaySpeech (BOB, "That doesn't need a decoration");
Ã,  }
}
Title: Re: Defualt Inventory Lines
Post by: Krazy on Wed 26/01/2005 04:39:34
Thank you it works woderfully now!