Problem with using inventory

Started by prinzach, Fri 09/05/2008 03:03:42

Previous topic - Next topic

prinzach

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?

Gilbert

Just write:
Code: ags
function oObject0_UseInv()
{
  if (player.ActiveInventory==itwenty) player.AddInventory (igambleliscence);
}


monkey0506

Okay what you want to do is use itwenty on oObject0? That should look like this:

Code: ags
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! :=

prinzach

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

Khris

You need to use itwenty on oObject0; did you test that?

prinzach

Yes, I've already tried that. It doesn't do anything.

monkey0506

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:

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

prinzach

no displays are showing. how do I fix it?

monkey0506

Have you enabled "Handle inventory-clicks in script"? If so...are you handling them? We'd need to see that code if you are.

prinzach

No, "Handle inventory-clicks in script" is set to false. Oh and i have version 3.0 in case that changes anything.

monkey0506

You could try enabling that option, then in on_mouse_click put this:

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

prinzach

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.

GarageGothic

Did you actually put the code inside the function on_mouse_click(MouseButton button)?

Khris

And iat is a pointer (variable) declared in the 2nd line.

monkey0506

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, and the tutorial I wrote 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).

prinzach

I moved it to the place you said to, but now it says:

X Error (line 152): undefined symbol 'eModeUse'

monkey0506

That's probably my fault because the cursor is actually named eModeInteract. Try replacing eModeUse with eModeInteract and see if that works.

prinzach

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.

Khris


SMF spam blocked by CleanTalk