Variable Problem With Inventory

Started by whitecrow, Thu 27/05/2004 01:03:11

Previous topic - Next topic

whitecrow

Hi all,
        I spent hours working this out last night, but am still confused about how to get it to work like I want it.. here's my prob.

GOAL: I want the character to only be able to pick up the item from the hotspot ONCE, every other time, the character will get nothing but a message.

WHAT I'VE DONE:
I've started a variable INT S_COUNT in the room script.
When the character picks up the Item from that hot spot, another script runs - (sorry I fogot the code)
S_COUNT += 1
(so the counter is now = 1)

Now what I want it to do is
{IF S_COUNT >= 1 {
display ("No more"); } NO MORE STUFF RUNS! }
//so you can't pick it up again, silly man.

THEN for no more actions to be run.

I've tried putting in a RETURN but it still runs..

i.e:
You will pick the item up for the first time.
try to pick it up again, message works fine.
use item, then pick it up again.
you get the item AND the message.

I tried EVERYTHING i could think of, I RTFM and all...but am still lost..please help...

thanks.

strazer

#1
Please post the exact script code you used, not pseudo-code.

You had the right idea with the variable, although if you leave the room, the variable resets to 0 because you declared it in the room script.
Better use GlobalInts (look them up in the manual).

Now, your code should look something like this:

...
  if (GetGlobalInt(77)) { // global integer is anything but 0
    Display("You already have it.");
  }
  else { // global integer is 0
    AddInventory(ITEMNUMBERHERE);
    SetGlobalInt(77, 1); // set global integer to 1
  }
...

I've used GlobalInt no. 77 here, but any number from 0 to 499 will do.

This is pretty basic stuff, so please try the Beginner's Forum next time. :)

Edit: Corrected valid GI numbers

whitecrow

Apologies for the wrong forum...wasn't reading well.


strazer

No problem.
Were you able to solve your problem then?

SMF spam blocked by CleanTalk