Having trouble with the inventory events part of the tutorial [SOLVED]

Started by mr.me, Thu 02/04/2009 03:10:51

Previous topic - Next topic

mr.me

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.

Trent R

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
To give back to the AGS community, I can get you free, full versions of commercial software. Recently, Paint Shop Pro X, and eXPert PDF Pro 6. Please PM me for details.


Current Project: The Wanderer
On Hold: Hero of the Rune

mr.me

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.

mr.me

Ok I've figured it out, the key sprite is very small and is in fact a pixel hunt, how do I fix this?

Trent R

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.
To give back to the AGS community, I can get you free, full versions of commercial software. Recently, Paint Shop Pro X, and eXPert PDF Pro 6. Please PM me for details.


Current Project: The Wanderer
On Hold: Hero of the Rune

mr.me

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.



Trent R

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
To give back to the AGS community, I can get you free, full versions of commercial software. Recently, Paint Shop Pro X, and eXPert PDF Pro 6. Please PM me for details.


Current Project: The Wanderer
On Hold: Hero of the Rune

mr.me

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.

Trent R

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. 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
Code: ags
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

To give back to the AGS community, I can get you free, full versions of commercial software. Recently, Paint Shop Pro X, and eXPert PDF Pro 6. Please PM me for details.


Current Project: The Wanderer
On Hold: Hero of the Rune

mr.me

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 "...".

Trent R

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.
Code: ags
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
To give back to the AGS community, I can get you free, full versions of commercial software. Recently, Paint Shop Pro X, and eXPert PDF Pro 6. Please PM me for details.


Current Project: The Wanderer
On Hold: Hero of the Rune

mr.me

I'm getting this:

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



mr.me

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);
}

mr.me

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.

Trent R

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?

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
To give back to the AGS community, I can get you free, full versions of commercial software. Recently, Paint Shop Pro X, and eXPert PDF Pro 6. Please PM me for details.


Current Project: The Wanderer
On Hold: Hero of the Rune

Pumaman

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.

Trent R

Gah! I totally forgot about that General Option!  :o

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


~Trent
To give back to the AGS community, I can get you free, full versions of commercial software. Recently, Paint Shop Pro X, and eXPert PDF Pro 6. Please PM me for details.


Current Project: The Wanderer
On Hold: Hero of the Rune

mr.me

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.

Khris

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.

Trent R

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
To give back to the AGS community, I can get you free, full versions of commercial software. Recently, Paint Shop Pro X, and eXPert PDF Pro 6. Please PM me for details.


Current Project: The Wanderer
On Hold: Hero of the Rune

SMF spam blocked by CleanTalk