Counter for specific Inventory Items [SOLVED]

Started by subspark, Fri 17/09/2010 16:52:08

Previous topic - Next topic

subspark

Hey guys,

I was trying to add a counter for players so that they must grab 2/2 items before proceeding. Once the last of the two items is collected you can no longer return back the way you came. There is no enforced specific order in which the items should be collected either which is why a simple counter should suffice.
Having said that, I'm having difficulty writing the code for it.

I've tried:
Code: ags
ChamberItemCounter +1;


...and also tried:
Code: ags
ChamberItemCounter = +1;


But all this returns an error.

I'm too uncertain to use:
Code: ags
ChamberItemCounter++;
because I'm not sure if that will keep counting and crash the game?

I know this sounds stupid. I just need a push in the right direction.

Thanks in advance, guys!
Sparky.

Ryan Timothy B

These all work the same and will all add 1 to the ChamberItemCounter int:
ChamberItemCounter += 1;
ChamberItemCounter = ChamberItemCounter + 1;
ChamberItemCounter++;


QuoteI'm too uncertain to use: ChamberItemCounter++;  because I'm not sure if that will keep counting and crash the game?
It shouldn't add to infinite and crash the game unless your logic is flawed. For instance:

I'm assuming this is a room with more than two items? Or is it just that they must grab 2 specific items before leaving and cannot return?
If it's two specific items, you wouldn't even need a counter, you could always just have a global bool that changes to True once you leave that room. Have it check on the room_Leave function to see if the player has the two specific items then change the doNotReturn bool.

Then on leaving the room you simply change the bool by doing this:
Code: ags
doNotReturn = (player.HasInventory(iKey) && player.HasInventory(iMap));


Then in the next room when you're trying to return, you simply do this:
Code: ags
if (!doNotReturn) player.ChangeRoom(x);
  else player.Say("I cannot return.");



If it's a room with multiple items, you could add the counter to the item pickup script itself. Just a simple ChamberItemCounter++;

When you try to return to that room from another room, you could simply do this:
Code: ags
if (ChamberItemCounter<2) player.ChangeRoom(x);
  else player.Say("I cannot return.");

subspark

#2
Thats more like it. I went with the second option because the two specific and only inventory items get used together in the next room rendering the bool useless.

I'll pipe your code into the game no and give it a whirl. :D

Cheers,
Sparky.

EDIT: Works great Ryan. Thanks for the assistance.

SMF spam blocked by CleanTalk