Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: mr.me on Thu 02/04/2009 03:10:51

Title: Having trouble with the inventory events part of the tutorial [SOLVED]
Post by: mr.me on Thu 02/04/2009 03:10:51
I'm a beginner making my first game and I don't know what I'm doing wrong.

I'm at this part:

"So, select "Interact object" and click the "..." button. When the player picks up the key we want two things to happen - firstly, the object on-screen needs to disappear, and secondly, the inventory item needs to be added to the player's inventory.

Here's my script solution. As an added bonus, I've also given the player 5 points for their trouble, but you don't need to have that third command:"

so that I can pick up the item. I have this script there like it said:

function oKey_Interact()
{
oKey.Visible = false;
player.AddInventory(iKey);
GiveScore(1);
}

Then it says I should be able to pick up the item (which is a key). When I try to pick it up with the hand in the test run nothing happens. Any help is appreciated, thanks.
Title: Re: Having trouble with the inventory events part of the tutorial
Post by: Trent R on Thu 02/04/2009 03:19:37
Nothing happens? Or does one happen and not the others?

Have you created the event correctly with the ellipses (...) button? Perhaps the object isn't big enough and leads to a pixel hunt.



~Trent
Title: Re: Having trouble with the inventory events part of the tutorial
Post by: mr.me on Thu 02/04/2009 03:52:12
I'm using the default key sprite that comes with AGS.
I clicked the "..." for the "Interact object"  and put the script I mentioned. When I click on the key in the test run nothing happens what so ever.
Title: Re: Having trouble with the inventory events part of the tutorial
Post by: mr.me on Thu 02/04/2009 03:54:30
Ok I've figured it out, the key sprite is very small and is in fact a pixel hunt, how do I fix this?
Title: Re: Having trouble with the inventory events part of the tutorial
Post by: Trent R on Thu 02/04/2009 04:20:54
A few ways to fix or workaround. (or use all 3!)

1) Make the object bigger.

2) Put a @OVERHOTSPOT@ in your status line. This will help the player know when the mouse is over the object.

3) Slightly-complicated scripting*:Create a hotspot around the object, link the hotspot's interact function (via the lightning bolt) to the same function of the object (copy-paste oKey_Interact into the box by the ..., and then press it to see if it is properly linked--it should jump to that function.) Finally, add hKey.Enabled=false; (or whatever you called the hotspot) after the line oKey.Visible = false;


~Trent
*At least more so than the tutorial.
Title: Re: Having trouble with the inventory events part of the tutorial
Post by: mr.me on Thu 02/04/2009 04:38:46
I'm sorry, but I don't understand.

1. Is there a way to do this with the current key image?(I'm using the one that came with AGS) Or do I have to make my own?

2. Where exactly do I put @OVERHOTSPOT@? I tried adding it in the script underneath "givescore" and got this:
Failed to save room room1.crm; details below
room1.asc(28): Error (line 28): Undefined token '@'

3. I copy past oKey_Interact into which box?

Sorry for being a pain, and thank you very much for your help.


Title: Re: Having trouble with the inventory events part of the tutorial
Post by: Trent R on Thu 02/04/2009 05:35:38
Well, since this isn't your main project--and you're just going through the tutorial.. I'd say don't bother.

Once you feel more comfortable with AGS and with Scripting, then come back to this and you'll understand it a lot easier. Or you might have figured it out on your own before then!


But if you still want me to explain, I totally can.


~Trent
Title: Re: Having trouble with the inventory events part of the tutorial
Post by: mr.me on Thu 02/04/2009 05:47:15
Actually this is going to be my first game I've worked the key into a puzzle, so I would very much appreciate it if you explained.
Title: Re: Having trouble with the inventory events part of the tutorial
Post by: Trent R on Thu 02/04/2009 06:12:26
I was coming back anyways, after I realized that I pretty much wrote a nicer-sounding RTFM post.


Quote1. Is there a way to do this with the current key image?(I'm using the one that came with AGS) Or do I have to make my own?
Basically no... You could make it a character, and use scaling... but that's really avoiding the problem and throwing in a useless solution. You can export sprites though (right-click and choose 'export to file')

Quote2. Where exactly do I put @OVERHOTSPOT@? I tried adding it in the script underneath "givescore" and got this:
@OVERHOTSPOT@ is a special keyword that is recognized by Gui labels. Read more about in the manual here (http://www.adventuregamestudio.co.uk/manual/Interface%20text.htm). It's simple and explains it better than I could.

Quote3. I copy past oKey_Interact into which box?
Answer coming soon! BRB Two answers:
Simple version: Just click the ...button under Interact with hotspot, and it'll create a new function in your script. Copy-paste all of the code into that function as well (plus the hotspot.enabled command).

Detailed explanation: The ...button makes a function for you automatically, but it isn't really necessary. If you had function I_AM_A_PIG() {
//do stuff in I Am A Pig function
}
that function in your script, you could put I_AM_A_PIG in any of the boxes under the events tab (lightning bolt). That just tells which function to call when you interact, or look, or whatever. What I meant before is that you can put the name of your object's Interact function there, since they'll do the same thing--and you won't have to duplicate the code.



Any questions?
~Trent

Title: Re: Having trouble with the inventory events part of the tutorial
Post by: mr.me on Thu 02/04/2009 06:50:03
I'm very confused about number 3. I'm supposed to be in the "Show this rooms: hotspots" and click "..." in the "Interact hotspot" right? If thats right I understand that.

Now I don't  understand what script and what order of each script I'm supposed to be adding when I click "...".
Title: Re: Having trouble with the inventory events part of the tutorial
Post by: Trent R on Thu 02/04/2009 07:03:17
Yeah, click the Interact hotspot (just like the Tutorial Part 3) and it should create hKey_Interact() (or whatever it's named).

Then put the following inside the curly brackets of the new function.
oKey.Visible = false;
hKey.Enabled=false; //make sure you add this line to oKey_Interact as well!
player.AddInventory(iKey);
GiveScore(1);



That's the simple version, and that's really all you need right now.
~Trent
Title: Re: Having trouble with the inventory events part of the tutorial
Post by: mr.me on Thu 02/04/2009 07:10:06
I'm getting this:

room1.asc(26): Error (line 26): Undefined token 'hKey'


Title: Re: Having trouble with the inventory events part of the tutorial
Post by: mr.me on Thu 02/04/2009 07:11:24
Quote from: mr.me on Thu 02/04/2009 07:10:06
I'm getting this:

room1.asc(26): Error (line 26): Undefined token 'hKey'




here are the scripts:

function oKey_Interact()
{
oKey.Visible = false;
hKey.Enabled=false;
player.AddInventory(iKey);
GiveScore(1);
}
function hkey_Interact()
{
oKey.Visible = false;
hKey.Enabled=false;
player.AddInventory(iKey);
GiveScore(1);
}
Title: Re: Having trouble with the inventory events part of the tutorial
Post by: mr.me on Thu 02/04/2009 07:18:21
I forgot I'm going to number the lines so you know which is which


23 function oKey_Interact()
24 {
25 oKey.Visible = false;
26 hKey.Enabled=false;
27 player.AddInventory(iKey);
28 GiveScore(1);
}
function hkey_Interact()
{
oKey.Visible = false;
hKey.Enabled=false;
player.AddInventory(iKey);
GiveScore(1);
}

Thank you very much for your help, I'm done for the day, so I'm not checking this thread again until tomorrow.
Title: Re: Having trouble with the inventory events part of the tutorial
Post by: Trent R on Thu 02/04/2009 18:06:56
First off, I'm not a moderator. So this comment is just coming from a friendly forum member:
Ever notice the link at the top right of your posts?
(http://dl.getdropbox.com/u/837372/Big%20arrow.jpg)
Not only just this keep in compliance with the rules, it's easier to edit than to triple post. :)


Second, did you create a hotspot around you oKey object? Did you name it hKey? Do you even know why you made it?


~Trent
Title: Re: Having trouble with the inventory events part of the tutorial
Post by: Pumaman on Thu 02/04/2009 18:09:41
I really wouldn't go down this hotspot-workaround route, it's unnecessarily complicated for what you need.

If the key is too small to easily click on, just export the sprite, make it bigger in your favourite paint program, and then import it back again.  Alternatively you could disable "Pixel-perfect click detection" under the Visual section in General Settings, which would allow the whole rectangular area of the key to be clickable, and not just the yellow pixels.
Title: Re: Having trouble with the inventory events part of the tutorial
Post by: Trent R on Thu 02/04/2009 18:14:16
Gah! I totally forgot about that General Option!  :o

I knew someone smarter would come and point out something obvious in this thread....


~Trent
Title: Re: Having trouble with the inventory events part of the tutorial
Post by: mr.me on Thu 02/04/2009 18:38:24
Sorry about the triple post.

Thank you very much for your help Trent R, even though I never figured it out.

Thank you Pumaman, changing pixel perfect to false fixed the pixel hunt.
Title: Re: Having trouble with the inventory events part of the tutorial [SOLVED]
Post by: Khris on Thu 02/04/2009 19:32:49
To address the original problem: set the key object to non-clickable, then use a hotspot to handle all the interactions.

I agree though that this might confuse a beginner and using a different sprite is a much better solution.
Title: Re: Having trouble with the inventory events part of the tutorial [SOLVED]
Post by: Trent R on Thu 02/04/2009 22:54:16
Lesson to learn: There are tons of ways to solve a scripting/design problem. Some work better than others, some are simpler than others.


~Trent
Title: Re: Having trouble with the inventory events part of the tutorial [SOLVED]
Post by: OneDollar on Thu 02/04/2009 23:14:36
Third (fourth?) option - if the key doesn't need to move you can add part of the background of the scene to the key's sprite, so that clicking on the fake background pixels around the key will also interact with it.