Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: on Wed 25/10/2006 18:48:57

Title: Character Replies to Inventory Item
Post by: on Wed 25/10/2006 18:48:57
I have a part where my main character wants to buy a bandana from another character. But he shouldn't be able to if he already has it. So under intaractiond for the selling character I have:

Use Inventory item on character
--Conditional - If the player has an inventory object
----Run Script: Character[Engel].Say("You already have the Bandana!")

But I get an error : Variable [ is already defined

What am I doing wrong?

Thanks!!!
Title: Re: Character Replies to Inventory Item
Post by: Candall on Wed 25/10/2006 19:23:33
I'm not sure where it's getting the singular opening brace.  I can only guess that it's from someplace before in your script.

As for that code, you should change Character[Engel] to cEngel, so that it now says:

cEngel.Say("You already have the bandana!");

Perhaps AGS thinks you have a variable called "[" because you mistakenly used that type of notation (which is used for arrays, not class instances) beforehand.
Title: Re: Character Replies to Inventory Item
Post by: on Wed 25/10/2006 19:29:15
It works now, THANKS! ;D
Title: Re: Character Replies to Inventory Item
Post by: Candall on Wed 25/10/2006 19:32:56
Quote from: SisteenStone on Wed 25/10/2006 19:29:15
It works now, THANKS! ;D

You're quite welcome :)
Title: Re: Character Replies to Inventory Item
Post by: strazer on Wed 25/10/2006 21:42:27
I think it was due to capitalization. AGS is case-sensitive, so it should have been
  character[ENGEL].Say("You already have the Bandana!");
(Also note the semi-colon at the end in case it wasn't in your script.)

But cEngel is easier, obviously.
Title: Re: Character Replies to Inventory Item
Post by: on Thu 26/10/2006 00:30:31
Okay so I have gotten all that working now, but there are a couple of more problems I've encountered.

First:
I want to include the speech sound(Enge627.wav) for when he says "You already have the bandana!" So i tried the following:

PlaySoundEx (627, 3)

But it doesn't seem to work!

Secondly,

I have the following under 'Use inventory of character'

--Conditional - if the player has an inventory item (3) <---The Bandana
-----Run script: cEngel.Say("You already have the bandana!");
                        AmountOfMoney += 2;

--Conditional - if inventory item was used (2) <---- The Cash
-----Player - Give Player the inventory item
-----Run Script: AmountOfMoney -= 2; 
                        cEngel.Say("Here you go, Enjoy the bandana!");


So if the player tried to buy it again Engel gives the money back do you don't spend any more. That works, but after Engel says "You already have the bandana" he says "Here you go enjoy the bandana!" Any reasons for this?

Thanks again!
Title: Re: Character Replies to Inventory Item
Post by: Gilbert on Thu 26/10/2006 02:25:07
PlaySound[Ex](), works wit files named like sound627.wav only.
If you like to follow the convenient speech sound naming format, you only need to do it like:

cEngel.Say("&627 You already have the bandana!");
Title: Re: Character Replies to Inventory Item
Post by: on Thu 26/10/2006 02:39:38
Wow, I have been doing that all along but I tried it before and it didn't work, but now it does... THANKS! ;D

Also, is there a way, under interactions, to make a Conditional -Ã,  If the player has an inventory item (3) = false... meaning only if the player DOESN'T have the inventory item will the event occur???
Title: Re: Character Replies to Inventory Item
Post by: Gilbert on Thu 26/10/2006 03:05:09
If you're using the interaction editor, you may try doing this (note the indenting):

Conditional - if the player has an inventory item (3)
Ã,  Ã, Stop running more commands
(do whatever you want here)
Title: Re: Character Replies to Inventory Item
Post by: Khris on Thu 26/10/2006 04:06:41
As you are already using RunScript-actions, why not switch completely?

The code would look like this:
if (player.ActiveInventory=iCash) {
  if (player.InventoryQuantity[iBandana.ID]>0) {
    cEngel.Say("You already have the bandana!");
  }
  else {
    player.AddInventory(iBandana);
    AmountOfMoney -= 2;
    cEngel.Say("Here you go, Enjoy the bandana!");
  }
}
else {
  cEngel.Say("I have no use for this.");
}
Title: Re: Character Replies to Inventory Item
Post by: Gilbert on Thu 26/10/2006 04:47:42
Because it's still easy to make errors at first, and even for experienced users.
if (player.ActiveInventory==iCash) {
Ã,  if (player.InventoryQuantity[iBandana.ID]>0) {
Ã,  Ã,  cEngel.Say("You already have the bandana!");
Ã,  }
Ã,  else {
Ã,  Ã,  player.AddInventory(iBandana);
Ã,  Ã,  AmountOfMoney -= 2;
Ã,  Ã,  cEngel.Say("Here you go, Enjoy the bandana!");
Ã,  }
}
else {
Ã,  cEngel.Say("I have no use for this.");
}



Just kidding of course! ;D