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?
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;
}
You should put this error message inside { } brackets after "else". Right now these brackets are empty inside.
Thank you, I would have never noticed that!
That's why you should always use proper indentation, that way the problem is clearly visible:
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;
}