Default Error Message Problem

Started by cdavenport, Thu 06/08/2020 14:21:17

Previous topic - Next topic

cdavenport


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


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;

}


Crimson Wizard

You should put this error message inside {  } brackets after "else". Right now these brackets are empty inside.

cdavenport

Thank you, I would have never noticed that!

Khris

That's why you should always use proper indentation, that way the problem is clearly visible:

Code: ags
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;
}

SMF spam blocked by CleanTalk