Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: on Mon 06/11/2006 16:45:58

Title: Problem with Look at Inventory Item Script [SOLVED?]
Post by: on Mon 06/11/2006 16:45:58
Hello!
I ve got a little Problem. I guess its nothin complicated, but I am not very common to write scripts and I couldnt find help in the tutorial or this forum. So, here it is:
I wann make my character pick up an Item (Its a box of cigaretts), have a look on it and find a lighter inside the box. So far it works. But now: I wanna show the first time, he looks on the box (the time he finds the lighter) another message displayed than the following times. (1. Time: "Oh! there is a lighter in the box!", after this always: "Thats a box of cigaretts."

I tried it this way:

// script for Inventory item 3 (Kippen): Look at inventory item

  int counter;   
  counter = 0;
     
   
  if (counter == 0) {
    Display("Hey! Da ist ja noch ein Feuerzeug in der Schachtel!");
    cEgo.AddInventory(ifeuer);
  }
  if (counter == 1) {
    Display("Das sind meine Kippen."); 
  }
 
  if (counter == 0) {
    counter += 1;
  }


But it does not work. I always get the first message.
Can somebody tell me, whats the misstake?

Thanks a lot!

Jan
Title: Re: Problem with Look at Inventory Item Script
Post by: SSH on Mon 06/11/2006 16:50:03
Becuase you initialise the variable to 0 every time you run the script. The variable needs to be outside the interaction function.

Or.... you could use my MultiResponse module (http://ssh.me.uk/moddoc/MultiResponse) which makes doing it sooo much easier...
Title: Re: Problem with Look at Inventory Item Script
Post by: on Mon 06/11/2006 16:53:50
OK, but I am a totally dummie... could you explain exactly, where i have to put the variable?
Title: Re: Problem with Look at Inventory Item Script
Post by: Mikko on Mon 06/11/2006 17:00:58
EDIT: Sorry, false information. Thanks SSH.
Title: Re: Problem with Look at Inventory Item Script
Post by: SSH on Mon 06/11/2006 17:05:17
No, that won't work, Mikko, as the variable is still local to the function.

Nachtpoet: edit the global script. Right at the top of the global script, put your "int counter;" line
then also remove the counter=0 line from the inventory interaction function.

That should do the trick.
Title: Re: Problem with Look at Inventory Item Script
Post by: on Mon 06/11/2006 17:06:37
OK, thanks again.

Jan
Title: Re: Problem with Look at Inventory Item Script
Post by: Khris on Mon 06/11/2006 18:58:30
To tidy things up a bit, you should use sth like feuerzeug_gefunden instead of counter, and you could move the int counter; line directly above the interaction function, that's the way I do it, but that's just a matter of personal preference.

The code could look like this:
  if (feuerzeug_gefunden)
    player.Say("Das sind meine Kippen.");
  else {
    player.Say("Hey! Da ist ja noch ein Feuerzeug in der Schachtel!");
    player.AddInventory(ifeuer);
    feuerzeug_gefunden++;
  }