Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: beenf on Sun 03/04/2011 13:03:26

Title: [SOLVED] Having problem with event: "Use inventory on Character"
Post by: beenf on Sun 03/04/2011 13:03:26
So my goal is to use an item on a character and after I've done that the door would open. So like he'd open the door for me.

I used this code:

function cVamp_UseInv()
{
if (player.ActiveInventory == iexampleitem) {
oDoorOpen.Visible = false;
oDoorClose.Visible = true;
player.LoseInventory(iexampleitem);
}

But ingame when I use the item on the character nothing happens.
I also wrote that code in the room.asc where the character and the door was.
if anyone has any idea what might be the problem thenplease help
Title: Re: Having problem with event: "Use inventory on Character"
Post by: Scavenger on Sun 03/04/2011 14:04:37
The problem is character interactions need to be specified on the character interaction pane, not the room pane. if you want that to happen, just go to the character editor, then the interaction editor and add an interaction for UseInv that way (AGS needs to link interactions to function names, so you can't just write a function and be done with it)

If the character appears in more than one room, just add an additional condition to the if function you have there:

if (player.ActiveInventory == iexampleitem && player.Room == exampleroom)
Title: Re: Having problem with event: "Use inventory on Character"
Post by: barefoot on Sun 03/04/2011 14:06:11
Just beat me scavenger  

Extra: the script gets added to the GlobalScript.asc

:=

barefoot
Title: Re: Having problem with event: "Use inventory on Character"
Post by: beenf on Sun 03/04/2011 14:15:04
Could u plz explain more how to add interactions ?
Title: Re: Having problem with event: "Use inventory on Character"
Post by: barefoot on Sun 03/04/2011 15:24:43
Quote from: beenf on Sun 03/04/2011 14:15:04
Couldyouplease explain more how to add interactions ?

check out events panel bottom right of screen. it will always relate to the character/object/hotspot you have selected. click on yellow bolt to enter events such as look, talk, use inventory etc.. it will auto put event in script where you can then set its conditions... such as if you look at an object you could display some text describing what it is you see.  etc

barefoot
Title: Re: Having problem with event: "Use inventory on Character"
Post by: beenf on Sun 03/04/2011 15:38:38
Where do I find Interaction Editor?
Title: Re: Having problem with event: "Use inventory on Character"
Post by: Matti on Sun 03/04/2011 15:49:36
(http://img823.imageshack.us/img823/2710/interactx.png)
Title: Re: Having problem with event: "Use inventory on Character"
Post by: beenf on Sun 03/04/2011 15:58:42
So I added the same function from my first post to cCharacter "Use inventory on character" interaction.
But now I get this error:
http://i36.photobucket.com/albums/e10/beenf/error.jpg
Did I do something wrong?
Title: Re: Having problem with event: "Use inventory on Character"
Post by: Ryan Timothy B on Sun 03/04/2011 16:04:04
On line 542 you have oDoorOpen. In the globalscript, it doesn't allow object name likes that, you'll have to refer to the object by the number.
Example (if oDoorOpen was object number 6 in that room):

You'd have to call it by this in the globalscript:
object[6].Animate(....

I would also check if you're actually in the room that has this object (if (Player.Room == 2) etc ). Unless this character that you're giving an item to, doesn't leave this particular room, then I wouldn't worry about it.
Title: Re: Having problem with event: "Use inventory on Character"
Post by: beenf on Sun 03/04/2011 16:15:55
Thnx for the help so far, but when I changed the object like Ryan told me to. Then I tested it.
When I walked in the room where the character and object was (the door) the game crashed and gave me this error:
http://i36.photobucket.com/albums/e10/beenf/error2.jpg

Title: Re: Having problem with event: "Use inventory on Character"
Post by: Matti on Sun 03/04/2011 16:25:22
Did you link the function properly?

(http://img858.imageshack.us/img858/7466/fadein.png)
Title: Re: Having problem with event: "Use inventory on Character"
Post by: beenf on Sun 03/04/2011 16:47:38
I did link it now from the Interaction you showed Matti. But I'm getting same error when going to Room 2
Title: Re: Having problem with event: "Use inventory on Character"
Post by: beenf on Sun 03/04/2011 17:36:33
Ohh I figured out now.
I had to open the room script under the edit room which I didn't do before :P

But I got a new question.
How can I change the characters Text after I have opened the door.
For example:
He told "Bring me a key and I will open the door" when the door was closed
But after I brought him key and door has opened he sais "The door has opened" or "I have no business with you anymore" etc
Title: Re: Having problem with event: "Use inventory on Character"
Post by: Matti on Sun 03/04/2011 18:09:03
Something like this for example:

if (oDoorOpen.Visible) cVamp.Say ("I have no business with you anymore");
else cVamp.Say ("Bring me a key and I will open the door");
Title: Re: Having problem with event: "Use inventory on Character"
Post by: beenf on Sun 03/04/2011 18:18:18
What if I want the cVamp to have new dialog??
Title: Re: Having problem with event: "Use inventory on Character"
Post by: Matti on Sun 03/04/2011 18:53:45
No offense, but you should really figure basic stuff like this out for yourself. Densming's video tutorials (http://www.youtube.com/user/densming#p/u/69/1Ml_DR76Cl4) might help you getting used to AGS.

What's the problem with starting a new dialog?
Title: Re: Having problem with event: "Use inventory on Character"
Post by: beenf on Sun 03/04/2011 19:02:42
Well, this is Beginners Technical Questions
And I just haven't had enough time to watch all the videos through
Title: Re: Having problem with event: "Use inventory on Character"
Post by: Khris on Sun 03/04/2011 19:18:07
Quote from: beenf on Sun 03/04/2011 19:02:42
Well, this is Beginners Technical Questions

While that's true that doesn't mean you aren't supposed to exhaust the other resources first before posting here. Don't be a smartass, listen to people. We don't care if you didn't have the time yet; watch them before posting the most trivial of questions here.
Title: Re: Having problem with event: "Use inventory on Character"
Post by: beenf on Sun 03/04/2011 19:22:24
Well I watched the Dialog tutorials already. I didn't find the answer I was looking. Or maybe I just didn't notice it.
If you ppl know a video tutorial for my problem then would be awesome to know about which one teaches that.
And sorry if I sounded Smartass
Title: Re: Having problem with event: "Use inventory on Character"
Post by: Matti on Sun 03/04/2011 19:28:37
What exactly is your problem?
Title: Re: Having problem with event: "Use inventory on Character"
Post by: beenf on Sun 03/04/2011 19:36:31
I want cVamp to start a different Dialog than he did when the door was closed.

I tried to figure how it works out myself, but failed
this is what I tried
function cVamp_Talk()
{
if object(0).Visible=true dVamp1.Start();
else if object(0).Visible=false dVamp.Start();

}
Title: Re: Having problem with event: "Use inventory on Character"
Post by: TomatoesInTheHead on Sun 03/04/2011 19:43:53
Quote from: beenf on Sun 03/04/2011 19:36:31
this is what I tried
function cVamp_Talk()
{
if object(0).Visible=true dVamp1.Start();
else if object(0).Visible=false dVamp.Start();
}


What are the error messages you got there? Not of any help?

- object is an array, its members are accessed with [], not ()
- comparisons are done with ==, a single = is only used to assign values
- conditions are enclosed in (), "if (object[0].Visible == true) dVamp1.Start();" ("== true" can be omitted here)

(all things you already did correct in the previous posts, why change it for the worse ;))
Title: Re: Having problem with event: "Use inventory on Character"
Post by: beenf on Sun 03/04/2011 19:53:48
I get this: GlobalScript.asc(576): Error (line 576): expected '('
even if i changed my ()'s to []'s and "=" to "=="

function cVamp_Talk()
{
if object[0].Visible == true dVamp1.Start();
else if object[0].Visible == false dVamp3.Start();

}

Title: Re: Having problem with event: "Use inventory on Character"
Post by: TomatoesInTheHead on Sun 03/04/2011 20:00:54
Yeah, read my post again... the error message gives the right hint. :)
Title: Re: Having problem with event: "Use inventory on Character"
Post by: beenf on Sun 03/04/2011 20:14:57
I'm sorry, but I still don't get it.
It's like there's a "(" which does not fit in the code. But I can't seem to find which one is it.
Edit: Or does it need an extra "("
Title: Re: Having problem with event: "Use inventory on Character"
Post by: Matti on Sun 03/04/2011 20:28:32
You need to put () around the conditions:

if (object[0].Visible == true) dVamp1.Start();
else if (object[0].Visible == false) dVamp3.Start();
Title: Re: Having problem with event: "Use inventory on Character"
Post by: beenf on Sun 03/04/2011 20:32:38
Hmm, that's what I did before
http://i36.photobucket.com/albums/e10/beenf/error3.jpg
Title: Re: Having problem with event: "Use inventory on Character"
Post by: Matti on Sun 03/04/2011 20:35:27
Yeah well, line 577 obviously is further down in your script. If we're supposed to help you, you should post the relevant code snippet.
Title: Re: Having problem with event: "Use inventory on Character"
Post by: beenf on Sun 03/04/2011 20:40:24
Ohh, that was the case. I tought it was something about the same lane, cause when I clicked the error it would highlight the 527th line