HasInventory - problems with a hotspot [Self-solved!]

Started by Lewis, Tue 22/11/2011 16:21:48

Previous topic - Next topic

Lewis

Hello!

I'm probably missing something really obvious here but I've been banging my head against a wall for ages with this, as well as scouring the internet. Anyway.

I require it to be so that a room change - activated by clicking a hotspot - only happens if the player has a certain inventory item. If not, a message is displayed instead.

I can get this to work, pretty much... except that the message STILL displays even when the player has this specific inventory item. It's just that it's displayed, and then the room change happens afterwards.

Code is below. What it's obviously doing is waiting for the script to finish before applying the room change, which means it displays the message as well. I want to get rid of the message as part of the HasInventory condition. Any help massively appreciated.


function hExit1_AnyClick()
{
 if (cJack.HasInventory(iPackage1)) {
 cJack.ChangeRoom(2);
 }
 Display("I shouldn't leave before I've spoken to Mike.");
}

***

UPDATE: Have solved this problem. Stumbled - via a completely separate bit of learning - on stuff about 'else'. Final code, in case anyone else is stuck with this sorta thing:

function hExit1_AnyClick()
{
  if (cJack.HasInventory(iPackage1)) {
  cJack.ChangeRoom(2);
  }
  else Display("I shouldn't leave before I've spoken to Mike.");
}
Returning to AGS after a hiatus. Co-director of Richard & Alice and The Charnel House Trilogy.

SMF spam blocked by CleanTalk