Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: prinzach on Fri 09/05/2008 03:03:42

Title: Problem with using inventory
Post by: prinzach on Fri 09/05/2008 03:03:42
basically, here is the script i have:

function oObject0_UseInv()
{
player.AddInventory (igambleliscence*itwenty);
}

I tried to save, but at the bottom of the page it says:

X Failed to save room room3.crm; details below
X Error (line 10): Operator cannot be applied to this type

I'm trying to use itwenty on oObject0 to get igambleliscence. Any suggestions?
Title: Re: Problem with using inventory
Post by: Gilbert on Fri 09/05/2008 03:19:54
Just write:
function oObject0_UseInv()
{
  if (player.ActiveInventory==itwenty) player.AddInventory (igambleliscence);
}

Title: Re: Problem with using inventory
Post by: monkey0506 on Fri 09/05/2008 03:32:23
Okay what you want to do is use itwenty on oObject0? That should look like this:

function oObject0_UseInv()
{
 if (player.ActiveInventory == itwenty) { // check which item the player used
   player.AddInventory(igambleliscence); // add the gambleliscence item
   player.LoseInventory(itwenty); // lose the twenty item
 }
}


If you want the user to keep the itwenty item, just remove the "player.LoseInventory" line. ;)

Arg...had to help my roommates carry up groceries and Gil beat me. But yes, what he said! :=
Title: Re: Problem with using inventory
Post by: prinzach on Sat 10/05/2008 02:28:17
Well, now it's letting me test the game, but I can't seem to exchange the two items while i'm testing.
I copied in exactly what monkey_05 _06 suggested, but if I try using itwenty on igambleliscence, or doing anything else, I don't lose itwenty or get igambleliscence.  ???
Title: Re: Problem with using inventory
Post by: Khris on Sat 10/05/2008 08:44:49
You need to use itwenty on oObject0; did you test that?
Title: Re: Problem with using inventory
Post by: prinzach on Sat 10/05/2008 20:53:59
Yes, I've already tried that. It doesn't do anything.
Title: Re: Problem with using inventory
Post by: monkey0506 on Sat 10/05/2008 21:44:09
Was the oObject0_UseInv function created automatically by AGS (by clicking the "..." button in the editor), or did you manually type it?

If you created the function yourself then it probably isn't linked properly. You'll need to make sure in the object's events pane (the lighting bolt icon) that the "Use inventory item on this object" function is set to oObject0_UseInv.

If that's properly linked you could use our old friend Display for a bit of debugging:

function oObject0_UseInv()
{
  Display("function linked and called properly");
  if (player.ActiveInventory == itwenty) { // check which item the player used
    Display("active inventory set properly. items should be added/lost!");
    player.AddInventory(igambleliscence); // add the gambleliscence item
    player.LoseInventory(itwenty); // lose the twenty item
  }
  else Display("active inventory not set properly!");
}


You should see the "function linked and called properly" and "active inventory set properly..." Displays. If your player's ActiveInventory property isn't being properly set, you should see a Display to this effect (however, if this is the case you shouldn't see any Displays). If you don't see any Displays then either the function isn't properly linked or the player's ActiveInventory isn't being set.
Title: Re: Problem with using inventory
Post by: prinzach on Sun 11/05/2008 02:38:01
no displays are showing. how do I fix it?
Title: Re: Problem with using inventory
Post by: monkey0506 on Sun 11/05/2008 03:44:06
Have you enabled "Handle inventory-clicks in script"? If so...are you handling them? We'd need to see that code if you are.
Title: Re: Problem with using inventory
Post by: prinzach on Sun 11/05/2008 20:37:46
No, "Handle inventory-clicks in script" is set to false. Oh and i have version 3.0 in case that changes anything.
Title: Re: Problem with using inventory
Post by: monkey0506 on Mon 12/05/2008 05:09:04
You could try enabling that option, then in on_mouse_click put this:

if (button == eMouseLeftInv) {
  InventoryItem *iat = InventoryItem.GetAtScreenXY(mouse.x, mouse.y);
  if ((iat == null) || (iat.IsInteractionAvailable(mouse.Mode))) iat.RunInteraction(mouse.Mode);
  else if (mouse.Mode == eModeUse) {
    mouse.Mode = eModeUseInv;
    player.ActiveInventory = iat;
  }
}


But it shouldn't really be necessary, so there may be something else going on here I think.
Title: Re: Problem with using inventory
Post by: prinzach on Tue 13/05/2008 03:34:43
I entered that but now at the bottom it says:

X Failed to save room room3.crm; see details below
X Error (line10): undifined simbol 'button'

also, I know I don't have an Inventory Item iat.
Title: Re: Problem with using inventory
Post by: GarageGothic on Tue 13/05/2008 03:42:37
Did you actually put the code inside the function on_mouse_click(MouseButton button)?
Title: Re: Problem with using inventory
Post by: Khris on Tue 13/05/2008 09:41:09
And iat is a pointer (variable) declared in the 2nd line.
Title: Re: Problem with using inventory
Post by: monkey0506 on Tue 13/05/2008 11:08:48
As Khris says iat is just a pointer-to-InventoryItem (or InventoryItem*) that should point to whatever InventoryItem the mouse is over. For more on pointers you should read the manual (http://www.adventuregamestudio.co.uk/manual/PointersForNewbies.htm), and the tutorial I wrote (http://americangirlscouts.org/agswiki/index.php?title=AGS_Pointers_for_Dummies) may offer further understanding.

Regarding that error message though, you probably don't want to put the code in the room script anyway or else you would only have proper inventory functionality within that room. The snippet I posted should go in the global script (GlobalScript.asc) within the on_mouse_click function (as GG said).
Title: Re: Problem with using inventory
Post by: prinzach on Sat 17/05/2008 02:25:15
I moved it to the place you said to, but now it says:

X Error (line 152): undefined symbol 'eModeUse'
Title: Re: Problem with using inventory
Post by: monkey0506 on Sat 17/05/2008 04:19:17
That's probably my fault because the cursor is actually named eModeInteract. Try replacing eModeUse with eModeInteract and see if that works.
Title: Re: Problem with using inventory
Post by: prinzach on Sat 31/05/2008 00:14:46
that works, but there's another error message:

X Error (line 153): undefined symbol 'eModeUseInv'

Again, if it changes anything, i'm using version 3.0.
Title: Re: Problem with using inventory
Post by: Khris on Sat 31/05/2008 01:07:49
try "eModeUseinv"