Adventure Game Studio

AGS Support => Advanced Technical Forum => Topic started by: dbuske on Sun 31/07/2011 22:59:59

Title: Object useinventory problem
Post by: dbuske on Sun 31/07/2011 22:59:59
function oTwist_UseInv()
{
cJudge.ActiveInventory = iBook;
Display("You use the Book to smash the twisted head.");
cJudge.LoseInventory(iBook);
FadeObjectOut(oTwist, 100, 2);
Display("There is a paper in the twisted head. You pick up the paper.");
cJudge.AddInventory(iPage);
}

Above is the code for it.  What is happening is I can't get the mouse to pick up the book in Inventory.
This code worked in another game and I don't get any error messages.
I was working in the global script before this putting looks in for all the inventory objects.
Could I have changed something by mistake?
Title: Re: Object useinventory problem
Post by: Khris on Sun 31/07/2011 23:10:20
The code needs to check for the active item, not set it:

function oTwist_UseInv()
{
  if (cJudge.ActiveInventory == iBook)  // only react if the book was used on oTwist
  {
    Display("You use the Book to smash the twisted head.");
    cJudge.LoseInventory(iBook);
    FadeObjectOut(oTwist, 100, 2);
    Display("There is a paper in the twisted head. You pick up the paper.");
    cJudge.AddInventory(iPage);
  }
  else Display("You can't use that here.");
}


This problem:
Quote from: dbuske on Sun 31/07/2011 22:59:59What is happening is I can't get the mouse to pick up the book in Inventory.
is unrelated to the code;
can you pick up other inv items? Did it work at first, then not or did it not work from the start?
Did you check the dimensions set in the InventoryWindow's property pane (ItemWidth, ItemHeight) versus the sprite size of the inventory item iBook?
Afaik, inventory clicks only register on the area determined by the dimensions, no matter how big the sprite is.
Title: Re: Object useinventory problem
Post by: dbuske on Sun 31/07/2011 23:18:00
Thanks for the great reponse.  I will check all that out
Title: Re: Object useinventory problem
Post by: dbuske on Mon 01/08/2011 12:46:04
It works if I click on the very top of the inv item.
I made the size of the inventory gui bigger and inv items smaller and still I have to
click near the top of the icon.
I am going to check the Inventory property pane now.
Title: Re: Object useinventory problem
Post by: monkey0506 on Mon 01/08/2011 12:51:01
Could you tell us the following information?

- The Width, Height, and Location (X, Y) of the GUI that has the InvWindow control on it.
- The ItemWidth and ItemHeight, set on the InvWindow control.
- The width and height of your inventory sprites.

This will help us determine what your problem is. You should be able to get all of this from the Properties pane of the GUI, InvWindow, and the sprites.
Title: Re: Object useinventory problem
Post by: Khris on Mon 01/08/2011 13:27:11
The InvWindow's ItemWidth and ItemHeight values determine the dimensions of the grid. Inventory item sprites are drawn with their top left corner at a grid cell's top left corner. The cell dimensions are also used to calculate which item was clicked from the mouse coordinates relative to the InvWindow's top left corner.

If the sprites are bigger than the cells, they will overlap; and the part outside the cell won't be clickable.
Title: Re: Object useinventory problem
Post by: dbuske on Tue 02/08/2011 17:57:13
Thanks for the replies. Yes some of the inventory sprites are larger than others and some wider.
I will check out the things you both mentioned right now.
By the way the game I am working on is a take off on "The Marionette" from Team Effigy.
First person, horror.  I am thinking about calling it "The Judge."
Title: Re: Object useinventory problem
Post by: dbuske on Wed 03/08/2011 13:48:57
Problem fixed, thanks to the responders.
I just made itemheight and itemwidth larger, now it works perfect.

My main big puzzle is the player has to collect musical notes. Then at  the end they will have to
put the musical notes on a piece of paper in the correct order. If they don't, they die.
If they do they autochangeroom to the conclusion end and survive.
I want to try hard to get it scripted on my own before asking for help. I used a fragment of Mozart music which you
have to solve puzzles to find.