Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Gribbler on Sat 12/08/2006 12:17:30

Title: removing an item form hotspot
Post by: Gribbler on Sat 12/08/2006 12:17:30
Hi all,

Im new to scripting and started to work on a game. Here's the thing. There's a hotspot in my room. When character is interacting with it he receives an item (then he uses it somewhere else and gets rid of it). When he gets back to the hotspot he can get the item again (and again and again). Now my question is how to do it so he would be able to get just once? I've used command "interact with hotspot" --> "add inv item".

Title: Re: removing an item form hotspot
Post by: hedgefield on Sat 12/08/2006 13:07:10
Because you can go back to the hotspot after you lose the item, I don't think you can avoid coding on this one. I would say using a global integer would do the trick.

Open up the Global Script and find the section:
#sectionstart game_start  // DO NOT EDIT OR REMOVE THIS LINE
function game_start() {
  // called when the game starts, before the first room is loaded

 
And add this below it:
SetGlobalInt (0, 0);  //if you already have global ints just change the first variable to an unused number.

Now under 'interact with hotspot' change "add inv item" to 'run script'. Click 'edit script' and add:

If (GetGlobalInt(0) == 1) {  //Player already used the hotspot
  Display("I don't need another one of those.");
}
If (GetGlobalInt(0) == 0) {  //Player hasn't used the hotspot yet
cEgo.AddInventory(iKey);  //Change iKey to the script name of the inventory item you want to the player to receive here.
SetGlobalInt(0, 1);
}


Now when you use the hotspot it will give the player an item, and the next time display a message saying you already got that item.
Title: Re: removing an item form hotspot
Post by: Gribbler on Sat 12/08/2006 14:38:18
Thanks largopredator! It worked just fine!

Title: Re: removing an item form hotspot
Post by: Khris on Sat 12/08/2006 22:40:08
There's no need to "init" the GI in game_start. And GIs are 0 from the beginning.

If you have many of these situations, keeping a list of GIs can get annoying, so in this case I'd suggest a room variable.

Open the room's script ({}-Button in Room Editor -> Settings), then addbool got_thingie=false; at the top outside any function.

In the interaction's script, use this;Ã,  if (got_thingie) {
Ã,  Ã,  Display("I don't need another one of those.");
Ã,  }
Ã,  else {
Ã,  Ã,  cEgo.AddInventory(iThingie);
Ã,  Ã,  got_thingie=true;
Ã,  }

Since you can use any name you want for the variable, the code becomes more readable, too.