Clicking on Inventory Items Does Nothing

Started by hocuspocus2, Thu 03/12/2020 05:25:17

Previous topic - Next topic

hocuspocus2

My game is in 1st person view and with no character, so you move around by clicking. As for the inventory system, I don't want multiple modes like Look At, Talk To, etc. I just want it so the player clicks on an item to uses it on other stuff or combine it with other inventories, like those 2000s-2010's point-and-click Flash games (Daymare Town, Cube Escape (though that series is still ongoing), Bars of Black and White, Submachine, etc.)

Here is a video I recorded of what happens:


Both 'Override built-in inventory window click handling' and 'Use selected inventory graphic for cursor' are set to True. I should mention that I'm also using the Bass template. Here's what I have for the Global Script:
Code: ags

// called when the game starts, before the first room is loaded
function game_start() {
  Mouse.Mode = eModeInteract;
  
  // register a GUI to use for the inventory bar
  //TwoClickHandler.InventoryGUI = gInventoryBar;

  // register a Label to use for action text
  //TwoClickHandler.ActionLabel = lblAction;

  // optionally set the popup distance for the inventory bar
  //TwoClickHandler.PopupProportional = 0.5;
  //TwoClickHandler.PopupDistance = 50;

  // optionally reverse the left and right mouse buttons
  //TwoClickHandler.ReversedClicks = true;
}

// called on every game cycle, except when the game is blocked
function repeatedly_execute() {
  if ((mouse.x < 100) && (Room.GetProperty("LeftAble"))) {
    mouse.SaveCursorUntilItLeaves();
    mouse.Mode = eModeLeft;
  } else if ((mouse.x > 1180) && (Room.GetProperty("RightAble"))) {
    mouse.SaveCursorUntilItLeaves();
    mouse.Mode = eModeRight;
  } else if ((mouse.y > 620) && (Room.GetProperty("DownAble")) && (GetLocationType(mouse.x, mouse.y) != eLocationHotspot)) {
    mouse.SaveCursorUntilItLeaves();
    mouse.Mode = eModeDown;
  } else {mouse.Mode = eModePointer;}
}

// called when a mouse button is clicked
function on_mouse_click(MouseButton button) {
  //clicking on edges code
  if (button != eMouseLeft) return; // do nothing
  
  if ((mouse.x < 100) && (Room.GetProperty("LeftAble"))) {
    player.ChangeRoom(Room.GetProperty("GoLeft")); // leftmost 100 pixels
  } else if ((mouse.x > 1180) && (Room.GetProperty("RightAble"))) {
    player.ChangeRoom(Room.GetProperty("GoRight"));  // 1280 - 100
  } else if ((mouse.y > 620) && (Room.GetProperty("DownAble")) && (GetLocationType(mouse.x, mouse.y) != eLocationHotspot)) {
    player.ChangeRoom(Room.GetProperty("GoDown"));  // 720 - 100
  }
}


The rest of the functions are either empty, have default lines from the template, or are irrelevant (ie character code or GUI code for specific rooms). The GUI for the inventory is called gInventoryBar.

When I try to use inventory functions like:

Code: ags
function iNeedle1_OtherClick()
{
  Display("aaaa please");
}


Nothing happens, either.

I tried switching mouse modes and removing all that room edges code to see if it's the cause but nothing changes. And uncommenting the TwoClickHandler line that registers the inventory GUI does nothing, either.

Khris

#1
You can see the cursor jump after you click, this is probably caused by switching to a different cursor mode (eModeUseinv) where the hotspot setting is off.
The TwoClickHandler script should call invitem_LookAt if you right click by default but otherwise work as desired.

Did you test a "use item on hotspot/object" interaction?

hocuspocus2

Yes, I've tested it on hotspots and it still didn't work, with or without the edges code.

Cassiebsg

Other_click does nothing in the BASS template, as far as I know.

Use LookAt and Interact events, instead.
However, clicking on the item it should pick it up. Are you sure you are actually clicking on the items and not on the image of the items? Check the size of the inventory items.
What is your game resolution? What size are the item sprites and what size is the inventory items size set to be?

Otherwise, start a new game and run the template game, you should then be able to pick up a inv item.
There are those who believe that life here began out there...

Crimson Wizard

#4
Quote from: Cassiebsg on Fri 04/12/2020 16:12:50
Other_click does nothing in the BASS template, as far as I know.

Use LookAt and Interact events, instead.

Yes, also "UseInv" event for using inventory items on other things. Other verbs are not used anywhere in this template, unless you modify script module.

I must also point, that changing mouse.Mode won't do much (other than changing cursor sprite, if you provided separate ones), as TwoClickHandler does not refer to active cursor mode, but instead sends either of three above commands directly (Interact, Look, UseInv).

hocuspocus2

The game resolution is 1280 x 720. The item sprites are 100 x 100. When I looked at the set inventory size in the GUI it was actually smaller (80 x 80), but even after changing it to the same size as the sprites, it does nothing. The Interact and LookAt item functions do nothing, either.

I have tried the "UseInv" in one room with no luck:
Code: ags
function hNeedle1_UseInv()
{
  if (player.ActiveInventory == iNeedle1) {
    Display("Yay!");
  }
}

Crimson Wizard

#6
Quote from: hocuspocus2 on Sat 05/12/2020 03:30:50
I have tried the "UseInv" in one room with no luck:
Code: ags
function hNeedle1_UseInv()
{
  if (player.ActiveInventory == iNeedle1) {
    Display("Yay!");
  }
}


Hmm, first of all you can try forcing this event. What will happen if you do this in room's "After fade-in" event script:

Code: ags

player.ActiveInventory = iNeedle1;
hNeedle1.RunInteraction(eModeUseinv);


Have you tried "Look" item event before (tested with mouse right click)?
Do other events, not related to inventory, work on hotspots and objects, is this a problem strictly with items (maybe they are not getting selected or something)?
Is TwoClickHandler script left untouched, or was modified?
Another random question, but do you ever call PauseGame in your scripts? I think TwoClickHandler does not do anything when game is paused.

EDIT: Ah, may be a silly question, but do you have any transparent GUIs covering whole screen or parts, where you could leave Clickable = true? This is pretty common mistake, but often overlooked when investigating problems with non-working mouse controls.

EDIT2: By the way, you said that "'Use selected inventory graphic for cursor' are set to True", but you are doing "mouse.Mode = eModePointer;" in repeatedly_execute, so you won't actually see item images on cursor as it will be switched away to pointer cursor all time.

hocuspocus2

So forcing the event does work, the cursor changes to the item's graphic and "Yay!" displays.
I did have problems with one room's hotspots that I've written about in the Beginners' Technical Questions, and that issue has been ruled as or at least suspected as a bug. And the "Look" event doesn't seem to work (though I'm not planning on having a "Look At" mode, either way). I'm pretty sure the TwoClickHandler was left untouched, I just commented its commands in the global script when I first started this game. All PauseGame events are from the template. All the other GUIs have their visibility set to False and don't cover the whole screen.

Cassiebsg

Have you started a new game with the BASS templet and run the game? Does it work there? If so, then it's something in your game that is interfering.
When I have this kind of problem and can't figure out what is wrong, I start by "removing" blocks of code from the script by adding a /* at start and */ at the end of the block I want to skip.

My suggestion would be exactly that, block all the code you have added and see if it fixes the problem, if it does, then it's a matter of finding the right block of code that is interfering.
There are those who believe that life here began out there...

Khris

#9
The TwoClickHander script (like any other script) can handle keypresses, mouseclicks and other events; commenting out its lines in the Global Script will not completely disable it.

Also, despite the occurrence of a weird bug (where based on changing the mouse position during a Display() command's waiting for a click or not, the game would proceed differently), the game's interaction handling was set up in a pretty impractical way and without a clear understanding of how scripts, user interactions and events work together.

Which means that the current mess is a direct consequence of the messy UI scheme the game uses in general, and imo you should start over.

Decide on how exactly you want the controls / cursor modes to work, use the proper interaction events and obviously remove any scripts from your game you aren't actually using.

hocuspocus2

I did try the BASS template by itself and it worked.
I'm gonna try Cassiebsg's advice, and if that doesn't work then I guess I will have to start over :(

hocuspocus2

Ok, so I finally figured it out.
I loaded up a new game with the BASS template and compared its scripts with mine. I've found that some template functions and statements were missing from mine, which was strange as I could have sworn I didn't delete anything and instead commented any lines in GlobalScript I wasn't using. One line in my game's TwoClickHandler.asc was also missing:
Code: ags
import static function Close();
As I still don't know what script headers really do, I never dared to tamper with them, so I have no idea why it was missing.

After correcting the game's TwoClickHandler and Global scripts, the items' Interact and LookAt functions started working. It didn't switch the cursor graphic though, and didn't work on a hotspot. That's when I found out that, when I was trying to investigate the problem, I've set the template's item property "InstantUse" to true, as I didn't know what it did beforehand. Now, the items switch the cursor graphic and work just fine.

My edge's cursor code was also interfering, where it switches back to eModePointer too quickly, so I modified it:
Code: ags
function repeatedly_execute() {
  if ((mouse.x < 100) && (Room.GetProperty("LeftAble"))) {
    mouse.SaveCursorUntilItLeaves();
    mouse.UseModeGraphic(eModeLeft);
  } else if ((mouse.x > 1180) && (Room.GetProperty("RightAble"))) {
    mouse.SaveCursorUntilItLeaves();
    mouse.UseModeGraphic(eModeRight);
  } else if ((mouse.y > 620) && (Room.GetProperty("DownAble")) && (GetLocationType(mouse.x, mouse.y) != eLocationHotspot)) {
    mouse.SaveCursorUntilItLeaves();
    mouse.UseModeGraphic(eModeDown);
  } else Mouse.UseDefaultGraphic();


It basically changes the cursor graphic alone instead of switching to a different mode if mouse is on an edge, and otherwise changes to DefaultGraphic.

SMF spam blocked by CleanTalk