player.activeinv always -1 when clicking on inventory item

Started by Ashera, Tue 17/05/2005 23:05:53

Previous topic - Next topic

Ashera

I'm trying to do a simple thing where you use one inventory item on another to get a third item.

Code: ags
Display ("On click: %d", player.activeinv);

// Toggle active inventory status
if (player.activeinv < 0)
{
	SetActiveInventory(19);
}
else if (player.activeinv == 19)
{
	SetActiveInventory(-1);
}

Display ("After script: %d", player.activeinv);

if (player.activeinv == 20)
{
	LoseInventory (19);
	LoseInventory (20);
	AddInventory (21);
	SetActiveInventory (21);
	Display ("Put glowies in cup to make glowcup!");
}


The first Display always shows "On click: -1", regardless of whether the cursor appears to have picked up the item or not. The toggle code was my attempt to get around that, but since activeinv always starts at -1 it's not that useful.

I've checked the inventory numbers; they're correct. What might be causing this?

Ashen

Where have you got this code?

Also, I'm a little confused about the purpose of the 'Toggle active inventory' part.
I know what you're thinking ... Don't think that.

Ashera

The code is in the "Interact object" section of inventory item #19. It used to be in "Use inventory on object", but it didn't do anything.

The "Toggle active inventory" part was my attempt to fix the -1 problem by manually toggling the item's active status. It didn't work.

Ashen

I'm still confused. Why are you checking/toggling the active state of item 19, then running an interaction that needs item 20 active?

Quote"Interact object" ... "Use inventory on object"
Have you just typed object when you mean inventory item, or have you actually put that code in the script for an object somewhere? (Sorry, obvious one, but I'm just trying to work through everything it might be.)

The way it should work, given your code, is:
Open the inventory.
'USE' item 20, to set it as active - the cursor should change to item 20's graphic.
Click item 19 to 'USE' item 20 on it, and run the if (player.activeinv == 20) interaction.
Get glowing cup.

How are you doing it? (Again, sorry to be so obvious - like I said, I'm confused by the 'check 19, use 20' thing in your script.)
I know what you're thinking ... Don't think that.

Ashera

Okay, ignore the initial toggle active inventory part then. It doesn't fix anything and it doesn't break anything, either. (i.e., it's not causing the problem.)

What happens is that I open the inventory, USE item 20, and the cursor changes to item 20's graphic. Then when I USE item 19, the cursor just changes to item 19's graphic instead of running the interaction.

I decided to add a debug message outputting the value for player.activeinv at each click. At every click (every time I USE an item), it says -1. So it's updating the cursor graphic, but it's not updating player.activeinv . Which is why the script's not doing anything.

Sorry for not being clear. :(

strazer

QuoteThe code is in the "Interact object" section of inventory item #19. It used to be in "Use inventory on object", but it didn't do anything.

That only works if the mouse is in UseInv mode, i.e. the active inventory item is the mouse cursor. That's how it's usually done.
Are you sure your mouse was in UseInv mode when you tried this?

QuoteThen when I USE item 19, the cursor just changes to item 19's graphic instead of running the interaction.

So do I understand correctly that you want to combine items by interacting with them when another item is active?
As I said, the usual way is to use the active inventory item (UseInv mode) on another item.

QuoteI'm trying to do a simple thing where you use one inventory item on another to get a third item.

Here's a step-by-step solution the usual (UseInv) way:

You need three inventory items:

Item A
Item B
Item C: The combined one

- "Inventory items" pane -> Select Item A -> "Interaction..." button
- "Use inventory on this item" -> "Run script"
Code: ags

  if (player.activeinv == ITEMB_NUMBER) { // if item B used on item A
    LoseInventory(ITEMA_NUMBER); // remove item A from player's inventory
    LoseInventory(ITEMB_NUMBER); // remove item B from player's inventory
    AddInventory(ITEMC_NUMBER); // add combined item to player's inventory
  }


- "Inventory items" -> Item B -> "Interaction..."
- "Use inventory on this item" -> "Run script"
Code: ags

  if (player.activeinv == ITEMA_NUMBER) { // if item A used on item B
    LoseInventory(ITEMA_NUMBER); // remove item A from player's inventory
    LoseInventory(ITEMB_NUMBER); // remove item B from player's inventory
    AddInventory(ITEMC_NUMBER); // add combined item to player's inventory
  }


Btw, which AGS version are you using?
In AGS v2.62 and below, "player" is just an alias for "character[EGO]" and is not actually the current player character. So if your player character is not named "EGO", your script may not work correctly.
AGS v2.7 always keeps "player" updated with the current player character.

SMF spam blocked by CleanTalk