Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: viktor on Sun 09/02/2014 20:11:24

Title: Character can get item only once
Post by: viktor on Sun 09/02/2014 20:11:24
Hy!

In my game I have a lump of dirt that the player can interact with. The first time the player interacts with the dirt he gets an item. Next time he tries to interact he doesn't get anything.

Now I could use for example

if (cEgo.HasInventory(aItem)==false)
{
cEgo.AddInventory(aInventoryItem);
}

The problem is that the player disposes of the item later in the game and he could get a new item from the dirt when he does. How can I prevent that?
Title: Re: Character can get item only once
Post by: DoorKnobHandle on Sun 09/02/2014 20:12:48
Search for Game.DoOnceOnly in the manual or use a boolean variable.
Title: Re: Character can get item only once
Post by: viktor on Sun 09/02/2014 20:14:08
I'll try...

EDIT: I'm looking at it and I don't really understand how this script works. I'll try some more but I may have to check back with you on this one.
Title: Re: Character can get item only once
Post by: viktor on Sun 09/02/2014 20:36:56
So I found this in the manual:

Code (ags) Select
if (Game.DoOnceOnly("open cupboard")) {
  GiveScore(5);
}


How do I rework this to work with my item? I'm guessing something like this:

Code (ags) Select
if (Game.DoOnceOnly("interact with object")) {
  cEgo.AddInventory(aItem);
}


But what is the interact with object actually suppose to be? And how do I make the character say something else after he already interacted with the object already?
Title: Re: Character can get item only once
Post by: Crimson Wizard on Sun 09/02/2014 20:39:54
Parameter in DoOnceOnly is just a unique string of your own choice that is "tagged" to this particular action, or a linked set of actions (if you can only do one of them in game).

Code (ags) Select

if (Game.DoOnceOnly("interact with object"))
  cEgo.AddInventory(aItem);
else
  cEgo.Say("I can't do this again");



Also: use [ code = ags ], not just [ code ] to post script examples.
Title: Re: Character can get item only once
Post by: viktor on Sun 09/02/2014 20:58:23
EDIT: Never mind... Solved it! Thank you :).
Title: Re: Character can get item only once
Post by: DoorKnobHandle on Sun 09/02/2014 20:59:39
Remove the { at the end of line 3. and the } on line 7.