UseInv - works inside the inventory but not outside (SOLVED)

Started by WHAM, Tue 22/09/2009 22:07:59

Previous topic - Next topic

WHAM

I have an inventory, and there are three items in this inventory (A, B and C)

When i select the items in the inventory by clicking them, my cursor becomes the inventory item, which I believe means, that my active inventory item is now the item shown.

If I use item A on item B in the inventory, it works and they combine into a new item by removing the two items and replacing them with a new one, so this far all seems okay, yes?

Now: I select a new item (C) from the inventory, everything looks ok and then I use the item on a character as follows:

Code: ags

function cSidecharacter_UseInv()
{
 if (player.ActiveInventory == iTemC) {
   cEgo.Say("Hello, would you like this item?");
 }
}


The result: the game thinks I just clicked on that character normally, causing my character to talk with the character!
What in the world am I doing wrong?
Wrongthinker and anticitizen one. Utterly untrustworthy. Pending removal to memory hole.

monkey0506

What does your inventory script actually look like? Is the player.ActiveInventory property being properly set? Is "Handle inventory clicks in script" set to true in the General settings pane?

More info plzkthxbai. ;)

WHAM

"Handle inventory clicks in script" is set to false, so my inventory script is... nonexistent, really. I'm working on my first GUI here.
Right clicking on an item in the inventory runs the "look" script and left click runs the "interact" script that is set to the item. That much works without a hitch.

In the global script file I have these, and they work ok.

Code: ags

function iTemB_Look()
{
cEgo.Say("It's a round peg");
}

function iTemA_Look()
{
cEgo.Say("There is a round hole in this piece of wood");
}

function iTemA_UseInv()
{
if (cEgo.ActiveInventory == iTemB) {
  cEgo.Say("It fits!");
  player.LoseInventory(iTemB);
  player.LoseInventory(iTemA);
  player.AddInventory(iTemC);
}
}


If I righ-click on the items A or B, I get the correct cEgo.Say lines for examining the items.
If I left-click on an item, the cursor graphic changes correctly, and by left-clicking 'iTemB', reopening the inventory and left-clicking on iTemA combines the items and I end up with iTemC in my inventory. As far as I understand, the player.Active.Inventory has to have been correctly set for this to work.
But as I explained in my forst post, for some reason the moment I click on a character or a hotspot, the game forgets I even tried to use an inventory item on them.

Code: ags

function cSidecharacter_Look()
{
cEgo.Say("That looks like sir Wellington on Hamshire");
}

function cSidecharacter_Talk() // After selecting an item in inventory, this script is still run!
{
  cEgo.Say("I think you look silly, sir");
  cBaddie.Say("No, dear sir, I believe it is YOU who looks silly!");
  cEgo.Say("Jolly good, sir!");
}
}

function cSidecharacter_UseInv() // This NEVER gets run, it seems
{
 if (player.ActiveInventory == iTemC) {
   cEgo.Say("Hello, would you like this item?");
 }
}



Do I have to set the"Handle inventory clicks in script" to true to get this to work? Why and when does the game lose the player.Active.Inventory?
If I'm still not giving enough info to you guys, can you  be more specific on what info or part of script do you need? If absolutely necessary, I can post a link to a copy of my entire global script file.
Wrongthinker and anticitizen one. Utterly untrustworthy. Pending removal to memory hole.

Crimson Wizard

#3
Can you look up into event handlers table for cSidecharacter and check if cSidecharacter_UseInv function is actually bound to "Use inventory" event?
Can it be that cSidecharacter_Talk function is set for "Use inventory" instead?
This is the first thing that comes to my mind.

WHAM

Wrongthinker and anticitizen one. Utterly untrustworthy. Pending removal to memory hole.

Mazoliin

Do you have a custom script for the normal mouse clicks?
If so, maybe there's something there that's the problem.

And you could try setting the ActivInventory manually and see what happens.

WHAM

Also: I just realized that, when I open the inventory and select an item, the inventory closes. That's okay by me.

Then, when I move my mouse back to the top of the screen to open the inventory GUI, the mouse cursor changes back to normal, even though I can still use the item I selected earlier on other items in the inventory and player.ActiveInventory is still correctly set.

Why does the cursor graphic have to go back to default setting when I open the GUI? Why does that happen?

I don't get this GUI business  >:(
Wrongthinker and anticitizen one. Utterly untrustworthy. Pending removal to memory hole.

WHAM

Quote from: Mazoliin on Wed 23/09/2009 15:59:08
Do you have a custom script for the normal mouse clicks?
If so, maybe there's something there that's the problem.

And you could try setting the ActivInventory manually and see what happens.

*Smacks self in the face*

I've set the mouse mode manually every time the player left-clicks (BUT I FORGOT I DID THAT!) to avoid other issues. Thanks for the tip, Mazoliin! Now the only big thing I need to do is rewrite the mouse-click script and this time: COMMENT IT PROPERLY!
Wrongthinker and anticitizen one. Utterly untrustworthy. Pending removal to memory hole.

SMF spam blocked by CleanTalk