Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: cdavenport on Thu 06/08/2020 14:21:17

Title: Default Error Message Problem
Post by: cdavenport on Thu 06/08/2020 14:21:17

I'm trying to implement a simple way to have AGS return a default error message if a wrong item is used on another object/hotspot/character in the scene, and this code below seems to work when I try and use anything other than the wrench to begin with. But when I use the wrench on the object, it works where I get "Okay. Done." but then it still displays the error message that comes after "else"...

Is there simple way to do this so it works correctly if the player uses the wrench on the object, but returns an error message if they try to use anything else?

Code (ags) Select


function oObject_UseInv()//USE *SOMETHING* ON OBJECT
{

if (cEgo.ActiveInventory == iWrench)  {

cEgo.Say ("Okay. Done.");

}

else {
 
}

  //ERROR - DEFAULT MESSAGE FOR WRONG ITEM
 

aMsg_trysomethingelse.Play();

  Display ("That didn't do anything. Maybe I should try something else?");

      // RESET CURSOR

            player.ActiveInventory = null;   // loose active inv
        mouse.Mode=eModeLookat;

}

Title: Re: Default Error Message Problem
Post by: Crimson Wizard on Thu 06/08/2020 14:22:35
You should put this error message inside {  } brackets after "else". Right now these brackets are empty inside.
Title: Re: Default Error Message Problem
Post by: cdavenport on Thu 06/08/2020 14:31:35
Thank you, I would have never noticed that!
Title: Re: Default Error Message Problem
Post by: Khris on Thu 06/08/2020 14:35:39
That's why you should always use proper indentation, that way the problem is clearly visible:

Code (ags) Select
function oObject_UseInv()//USE *SOMETHING* ON OBJECT
{
  if (cEgo.ActiveInventory == iWrench)  {
    cEgo.Say ("Okay. Done.");
  }
  else {
 
  }

  // ERROR - DEFAULT MESSAGE FOR WRONG ITEM
  aMsg_trysomethingelse.Play();
  Display ("That didn't do anything. Maybe I should try something else?");

  // RESET CURSOR
  player.ActiveInventory = null;   // loose active inv
  mouse.Mode = eModeLookat;
}