Since I've had a lot of people complaining about the inventory in the last couple of episodes of Technobabylon, I've decided to try and change it to a more BaSS flavour. Currently, I've got a GUI at the bottom that slides out when the mouse is over it, and I've now placed an inventory box into it. The problem now is that every click on objects in the custom window causes it to "Look at" the object, even though the custom mouse clicking script is supposed to cause "left click interact, right click look".
This only happens in the new, custom inventory though. The old one has absolutely no problem reacting seperately to the left and right clicks. Is there something I've missed when making this new inventory?
This bit's for the mouse clicking:
function on_mouse_click(MouseButton button) {
// called when a mouse button is clicked. button is either LEFT or RIGHT
if (button == eMouseLeft || button == eMouseLeftInv) {
if(mouse.Mode==eModeTalkto){ProcessClick(mouse.x, mouse.y, eModeTalkto);}
else {
if (GetLocationType(mouse.x, mouse.y) == eLocationNothing) ProcessClick(mouse.x, mouse.y, eModeWalkto);
else {
if (player.ActiveInventory != null) ProcessClick(mouse.x, mouse.y, eModeUseinv);
else ProcessClick(mouse.x, mouse.y, eModeInteract);
}
}
}
else if (button == eMouseRight || button == eMouseRightInv){
// right-click
if(mouse.Mode==eModeTalkto){mouse.Mode=6;return;}
if(player.ActiveInventory!=null){player.ActiveInventory=null;mouse.Mode=6;return;}
ProcessClick(mouse.x, mouse.y, eModeLookat);
}
}
The way I'm reading this is that for left-clicking an item it would try to walk to the item..since GetLocationType returns eLocationNothing for InventoryItems. So, 1) do you have inventory click handling enabled in the script via the Game Settings pane, and if so, 2) do you have some script that converts eModeWalkto clicks on inventory items into eModeLookat?
Ahh, I'd forgotten about handling inventory clicks in the script. I've set that to "true" now, but you're right - now the character tries to walk to where the inventory is.
Now that you mention it, I can see how it arrives at "walk", but how is interacting with inventory different in the script to interacting with things in the room? The player will still use things in the room, just not the inventory. Is it something to do with
if(GUIControl.GetAtScreenXY(mouse.x, mouse.y)==InvNewInventory){}
to tell it to notice the new inventory underneath it?
The reason it's different is, as I said, GetLocationType returns eLocationNothing for inventory items. For hotspots and objects within a room it would return eLocationHotspot and eLocationObject (respectively). So now the problem is your logic..I'd suggest something more like this:
function on_mouse_click(MouseButton button) {
// called when a mouse button is clicked. button is either LEFT or RIGHT
if (button == eMouseLeft || button == eMouseLeftInv) {
if (mouse.Mode == eModeTalkto) {
ProcessClick(mouse.x, mouse.y, eModeTalkto);
}
else {
if (GetLocationType(mouse.x, mouse.y) == eLocationNothing) {
// mouse was over nothing, OR inventory item
InventoryItem *iat = InventoryItem.GetAtScreenXY(mouse.x, mouse.y);
if (iat == null) ProcessClick(mouse.x, mouse.y, eModeWalkto); // mouse was not over an inventory item
else if (iat.IsInteractionAvailable(eModeInteract)) iat.RunInteraction(eModeInteract); // mouse was over item, try interaction
else player.ActiveInventory = iat; // if no interaction was defined, set active inventory
}
else {
if (player.ActiveInventory != null) ProcessClick(mouse.x, mouse.y, eModeUseinv);
else ProcessClick(mouse.x, mouse.y, eModeInteract);
}
}
}
else if (button == eMouseRight || button == eMouseRightInv) {
// right-click
if (mouse.Mode == eModeTalkto) {
mouse.Mode = eModePointer; // eModePointer is mode 6
return;
}
if (player.ActiveInventory != null) {
player.ActiveInventory = null;
mouse.Mode = eModePointer;
return;
}
ProcessClick(mouse.x, mouse.y, eModeLookat);
}
}
You'll notice the changes that I made when the location type was eLocationNothing. Since inventory items are treated as nothing by GetLocationType, you have to check for inventory items within that clause.
The rest of it looks fine to me, but note that I didn't actually test my revisions. ;)
Merci beaucoup! It works just fine like that. Based on that, I managed to add a couple more bits to take into account looking at the inventory, and using inventory items on each other, and it all seems to be running quite capably!
Once again, many thanks!
You're definitely welcome. I've always thought it strange that GetLocationType returns eLocationNothing for inventory items (although interestingly Game.GetLocationName does not ignore inventory items). Sometimes you just have to look out for quirks like this though.. ;)