Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: limeyman1992 on Sat 26/06/2010 02:08:04

Title: (Solved!) A NEW Problem with Key_Interact functions
Post by: limeyman1992 on Sat 26/06/2010 02:08:04
Okay, after fixing my last problem I encountered a new one. When I attempted to play the game, it would not let me pick up the key. Here's the script again if you can understand why it's not working:

function okey_Interact()
{
okey.Visible = false;
player.AddInventory(iKey);
Display("I picked up the key. I hope it fits the cuffs. If not then that's just teasing...");
}

And here's the warning message it gave me after the game wouldn't let me pick up:
Error: prepare_script:error -18 (No such function in script) trying to run 'Key_interact' (Room 1)
Title: Re: Problems with Key_Interact functions
Post by: Calin Leafshade on Sat 26/06/2010 02:30:52
remember you have to create a new inventory item in the list on the right hand side in the project tree..

also its a good idea to get into using naming conventions.

so the object 'key' might be called oKey
and the inventory item key might be iKey.
Title: Re: Problems with Key_Interact functions
Post by: Dualnames on Sat 26/06/2010 02:30:58

function key_Interact(){
key.Visible = false;
player.AddInventory(ikey);                //<---- This is the line the AGS had a problem with
Display("I picked up the key. I hope it fits the cuffs. If not that's just teasing...");
}
Title: Re: Problems with Key_Interact functions
Post by: limeyman1992 on Sat 26/06/2010 11:21:41
I tried using okey and ikey but that didn't work. I'm going to recheck the inventory section of the tutorial to make sure I've not missed anything
Title: Re: Problems with Key_Interact functions
Post by: Dualnames on Sat 26/06/2010 12:10:56
Quote from: limeyman1992 on Sat 26/06/2010 11:21:41
I tried using okey and ikey but that didn't work. I'm going to recheck the inventory section of the tutorial to make sure I've not missed anything

The object must be given a script name!
And the inventory has already a script name, starting with i (I assumed its iKey)


function key_Interact(){
object[0].Visible = false;
player.AddInventory(inventory[1]);                //<---- This is the line the AGS had a problem with
Display("I picked up the key. I hope it fits the cuffs. If not that's just teasing...");
}


This may work just by referencing ID numbers instead of script names.
Title: Re: A NEW Problem with Key_Interact functions
Post by: Vince Twelve on Sat 26/06/2010 13:55:05
Actually, it looks like the problem is that the function is incorrectly linked to the item's interactions.

This function is called okey_Interact() but it's looking for Key_interact().  You can either rename this function (make sure to pay attention to capitals.  Capital 'K', lower case 'i') or you can go into the room editor, switch to object editing, choose the key, then press the lightning button.  Look at the function named here under interact and make sure it matches the one in your script.  If you press the ... button, it should go straight to it.
Title: Re: A NEW Problem with Key_Interact functions
Post by: limeyman1992 on Sat 26/06/2010 14:26:28
Thanks everyone for helping, I've fixed it now ^_^