How do i make a hotspot disappear after the character interacted with it?

Started by Davostros, Thu 27/10/2011 23:59:10

Previous topic - Next topic

Davostros

My question is:
Once my character has interacted with a hotspot and got an item from it, how do i make the character say something different about that hotspot? Like "There's nothing usefull there anymore." Or simply make the hotspot disappear. I just want to avoid the character saying "hey there seems to be something interesting behind that!" when it already got it in its inventory. I mean i don't have any double inventory item issues, the item is only pickable once, but i don't like the fact that if i use interact with the hotspot again, the character will still say the same thing as the first time and walk over the hotspot again when there isn't anything to do there anymore. Please Help  :-X

monkey0506

There's various ways you could accomplish this. The most user-friendly might not be to have the hotspot "disappear" as you say, but to generate an alternate message as you originally indicated. For that, you can use the Game.DoOnceOnly function:

Code: ags
function hBookshelf_Interact()
{
  if (Game.DoOnceOnly("Interact bookshelf"))
  {
    player.Say("Hey, there seems to be something interesting behind that!");
    // get inventory item, or whatever you're doing here
    return; // this aborts the rest of the function, basically meaning we don't have to wrap everything else in an 'else' block ;)
  }
  player.Say("There's nothing useful there any more.");
}


If you did want the hotspot to just disappear instead, you can use Hotspot.Enabled for that:

Code: ags
// ...player interacts with the bookshelf (or whatever it is!)
  hBookshelf.Enabled = false; // turn the hotspot off, so the player can't interact with it.


If you wanted to re-enable it, just set it to true instead of false.

Khris

Very basic question that has been asked and answered countless times.
And the scripting tutorial in the manual contains a solution to this problem that allows more than two different reactions.

I couldn't find a thread dealing with this on the spot though; it's high time somebody put together a current and organized BFAQ again.
The first link in the readme thread leads to an empty page, and the one further down leads to a FAQ that still recommends the use of GlobalInts.

Any volunteers? :=

Davostros

Thanks a lot. You really helped me here it's working perfect.

SMF spam blocked by CleanTalk