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
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...
OK, but I am a totally dummie... could you explain exactly, where i have to put the variable?
EDIT: Sorry, false information. Thanks SSH.
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.
OK, thanks again.
Jan
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++;
}