Inventory Items not-selectable

Started by Mr Games, Mon 19/11/2018 19:17:45

Previous topic - Next topic

Mr Games

I have made a serious effort to solve this problem by myself.

I've created a custom inventory that appears when a button is clicked, and the item is showing up correctly after acquisition.
However, clicking on the item does not change the pointer to its cursor sprite.

For the inventory GUI I'm just using the code from the DemoQuest template

Code: ags
   function ShowInventoryWindow() {
// 
// This function opens the inventory selection GUI.
//-------------------------------------------------------------------
	mouse.Visible = true;
	gGui1.Visible = true;						// Show custom inventory window
	mouse.Mode = eModeInteract;			// switch to the Use cursor (to select items with)
  mouse.UseModeGraphic(eModePointer);	// But, override the appearance to look like the arrow


From the item itself (iRatSkull) I created an event linked to this function

Code: ags
function iRatSkull_Interact()
{
  cSmileyface.ActiveInventory = iRatSkull;
}


Is there something obviously wrong here? :(

Crimson Wizard

#1
There was a very similar question just recently. You are not posting your "on_mouse_click" code, but seeing iRatSkull_Interact code it seems that you went same way as the topic starter in that other thread, - by handling item selection in particular "interact" event, - which is very non-optimal. Perhaps the suggested solution will also work for you:
http://www.adventuregamestudio.co.uk/forums/index.php?topic=56594.msg636597485#msg636597485

Mr Games

Thank you. I had checked that thread, but thought it might be different since they are making a game specifically with one mouse type only.

I attempted your suggested solution, fitting the code into the on_mouse_click section, but I think I must have made a mistake somewhere as I still cannot select the item in the inventory.

Code: ags
function on_mouse_click(MouseButton button) // called when a mouse button is clicked. button is either LEFT or RIGHT
{
  if (IsGamePaused() == 1) // Game is paused, so do nothing (ie. don't allow mouse click)
  {
  }
  else if (button == eMouseLeft) 
  {
    Room.ProcessClick(mouse.x,mouse.y, mouse.Mode);
  }
  else if (button == eMouseLeftInv) { // EDITED CODE STARTS HERE
    // if no item selected, then select one
    if (player.ActiveInventory == null)
        player.ActiveInventory = inventory[game.inv_activated];
    // otherwise use item on item
    else
        inventory[game.inv_activated].RunInteraction(eModeUseinv);
} else if (button == eMouseRightInv) {
    // if some item is selected, then deselect it
    if (player.ActiveInventory != null)
        player.ActiveInventory = null; //EDITED CODE ENDS HERE
}
  else // right-click, so cycle cursor
  {   
    mouse.SelectNextMode();
  }
}


Sorry if I'm out of my depth, I just find I learn a lot more by tackling things head on.

Crimson Wizard

#3
Hm, two things to double-check:
1) In General Settings -> Inventory -> "Override built-in inventory handling" (should be True in your case);
2) In your code the mouse clicks are skipped if the game is paused. Does the inventory window pause your game (has "Pause game when shown" type)?
In that case I suggest first check inventory clicks, then do like:
Code: ags

if (IsGamePaused() == 1) // Game is paused, so do nothing (ie. don't allow mouse click)
    return;

and then continue with the regular clicks.

(But you will probably have to adjust that further as you continue with development)

Mr Games

Thank you, Crimson Wizard

Unfortunately still can't fix it :(

After my previous post I immediately realised I'd need to check the "Override built-in inventory handling". But that didn't fix it.

The GUI type is "Normal, initially off". I have an object in a specific room which, when clicked on, displays the inventory.
As I mentioned before, the item displays fine after it is collected, but clicking on it doesn't change the cursor ><

I'll keep experimenting... 

Crimson Wizard

Quote from: Mr Games on Mon 19/11/2018 22:00:38
The GUI type is "Normal, initially off". I have an object in a specific room which, when clicked on, displays the inventory.
As I mentioned before, the item displays fine after it is collected, but clicking on it doesn't change the cursor ><

Few more questions: does this inventory actually belong to the player, or to some dummy character?
Which cursor type do you click items with?
Can you put a breakpoint under "else if (button == eMouseLeftInv)" and see how it goes there?

Khris

#6
Quote from: Crimson Wizard on Mon 19/11/2018 21:23:241) In General Settings -> Inventory -> "Override built-in inventory handling" (should be True in your case);

Should it though? Because afaik the default mechanism will pick up the item when the player interacts with it. The more pertinent question here is how the game differs from the Default Game so that interacting with inventory items doesn't work. It could be the infamous item size issue:
The first thing I would do is check the inventory window's ItemWidth and ItemHeight. If you haven't added a second inventory item yet, you probably haven't noticed that the item size is set way too small. Which means the items will overlap, and only react to clicks in their top left corner.

And one doesn't need function iRatSkull_Interact() either; it should just work. (Besides, adding a function like that for each item individually is not only really tedious, it also almost always means you're going the wrong way about implementing some mechanism. AGS is easily powerful enough to let you implement UI behavior globally. The proper way to do this, if you decided to implement custom inv handling, is to use player.ActiveInventory = inventory[game.inv_activated]; in the eMouseLeftInv block.)

Mr Games

Crimzon Wizard:

-My player character is called cSmileyface in the script. I assumed it would belong to him by default. Where should it be linked to him?

-According to the script, the cursor switches to interact in the inventory, but I actually use interact cursor by default, with a pointer sprite.

-I'm not sure how to do a breakpoint, I assume you don't mean separating the code there since that causes an error and I can't load the game.

Khris:

-My game resolution is 1920x1080. The Inventory window takes up most of the GUI's space, at 815x441 pixels.
However, "item height/width" is 20x30. The sprite seems to ignore this. Should I make these values larger?

Khris

Definitely. How big are your inventory item sprites? Item width / item height is the grid size of the inventory window, in pixels. You likely have sprites that are much bigger than 30x20 pixels, I guess?

Mr Games

Thank you, that solved it!

So item height/width is the space the item takes up in the inventory window, regardless of the sprite size. Now I understand. First-timer and all ^^; and I was thinking the code was messed up.

SMF spam blocked by CleanTalk