I'm currently working on writing a verb coin GUI and I've run into some trouble. I want the verb coin to appear for inventory items, same as for hotspots. So, if you hold down the left mouse button it should appear after a little while. The problem is, that's not what happens.
I think I've narrowed it down to this segement of code, found in repeatedly_execute:
if (HasClicked && mouse.IsButtonDown(eMouseLeft))
{
Display("TEST");
if (ClickTimer < 10)
{
ClickTimer++;
}
else
{
gVerbCoin.X = ClickedX - 47;
gVerbCoin.Y = ClickedY - 30;
gVerbCoin.Visible = true;
ClickTimer = 0;
}
}
else if (HasClicked)
{
Display("TEST2");
ProcessClick(ClickedX, ClickedY, eModeWalkto);
ClickTimer = 0;
HasClicked = false;
}
If I hold down the left mouse button on a regular hotspot, this code first displays TEST and then TEST2, as would be expected since I released the button to click away the TEST message. However, when I hold down the left mouse button over an inventory item nothing happens until I release the button, at which point TEST2 is displayed.
This has me very confused. Since TEST2 is displayed, HasClicked must be true. And since TEST isn't displayed, mouse.IsButtonDown(eMouseLeft) must be false. If this is correct, why the delay until I release the button before displaying TEST2? If IsButtonDown is false, the script should have displayed TEST pretty much as soon as I had clicked on the item.
I'd be very grateful if someone could explain what's going on here and how I could fix it.
We need more info.
I'll guess at the solution though.
Assuming that HasClicked and ClickedX/Y are set inside on_mouse_click, to make the code work with inventory items, make sure to do two things:
-check "handle inventory clicks in script" in the general settings pane
-remember that left clicks on inv items trigger on_mouse_click(eMouseLeftInv), not on_mouse_click(eMouseLeft).
Thanks for the help, but I really don't know what more info to give.
I know about both "handle inventory clicks in script" and eMouseLeftInv. I've got pretty much everything else working about the inventory except this. I can just simply click on the inventory item to use them as a selected item, which would lead down the TEST2 path in the code I posted. I can also right click to close the inventory or, if an item is selected, to uselect it. So the problem does not lie in the game not recognising my clicks.
eMouseLeftInv could be the culprit in this, but since you can't do something like "if (mouse.IsButtonDown(eMouseLeftInv))" I don't think that's it.
HasClicked, ClickedX and ClickedY are indeed set in on_mouse_click, but they're not really relevant to this, are they? Except for the fact that HasClicked is true, that is.
I got the code to work by setting the Clickable property of the GUI containing the InvWindow to "No".
Hey! I got it to work! Took a bit more work than just making the GUI non clickable though. The problem with just doing that was that I needed to catch the clicks that were made on it to be able to do something with the inventory items that were being clicked on.
What I did was to make the GUI non clickable and then when the game has registered a click and the inventory is visible it makes it clickable again. That way I can check out if there was an inventory item under the mouse at the time of the click and set HasClicked and all that stuff. Then I just make it non clickable again and let the script in repeatedly execute do its work.
Kind of a weird way around it and I'm sure there's a more elegant way of doing it. But hey, it works and that's all that matters. Thanks for the help!