Coding is really not something I'm good at, and it's been a while since I last tried to code in AGS. I can't seem to make this work properly.
Here's my code:
function on_mouse_click(MouseButton button) {
// called when a mouse button is clicked. button is either LEFT or RIGHT
if (IsGamePaused() == 1){
//if the game is paused do nothing.
}
else { //Finally if the game isn't paused, run normal room interation stuff
if (button == eMouseLeft) {
ProcessClick(mouse.x, mouse.y, mouse.Mode );
}
else if (button == eMouseRight) { // right-click, so cycle cursor
mouse.SelectNextMode();
}
}
if ((button == eMouseLeftInv) && (Mouse.Mode == eModeGreetTou)) {
player.ActiveInventory=InventoryItem.GetAtScreenXY(mouse.x, mouse.y);
Mouse.Mode=eModeUseinv;
}
else if ((button == eMouseLeftInv) && (Mouse.Mode == eModeExamine)) {
inventory[game.inv_activated].RunInteraction(mouse.Mode);
}
else if ((button == eMouseLeftInv) && (Mouse.Mode == eModeUseinv)) {
inventory[game.inv_activated].RunInteraction(mouse.Mode);
}
else if (button == eMouseRightInv) { // right-click, so cycle cursor
mouse.SelectNextMode();
}
}
GreetTou is the equivalent of Interact and Examine is the equivalent of Lookat.
I've put in display messages for the event that I interact with or look at the inventory item I'm using to test this on. The messages never pop up, so it seems that the above code isn't working.
I can't figure out what the problem is, though. Any help would be appreciated. :=
The first thing I noticed was that your braces (appear) to be off in that your "inventory clicks" script is handled outside the else-clause of the "if (IsGamePaused() == 1)" statement. In other words, your inventory-click scripts will be run whether the game is paused or not. If your inventory GUI is Popup Modal then this is fine, it just seems a bit silly having a check whether the game is paused (and saying "if [it] is paused do nothing"), an else-clause for all the non-paused code, and then a completely different if-structure for the inventory clicks.
The next thing I noticed was that in your inventory-clicks script, you're using Mouse.Mode instead of mouse.Mode. Seeing as the Mode property of the Mouse structure isn't static I'm actually surprised this compiles ...Apparently I was wrong. Turns out that the Mode property
is static, just generally it is accessed using the
mouse instance (as this is also the only way to access the non-static X/Y properties).
I don't see any obvious reason why your Display statements wouldn't be turning up at all. In a case like this I would use lots of Displays though. It's a great debugging tool. I'd probably display a message right before your inventory-click scripts and then one right after, as well as one from each branch. That way I would be able to tell exactly which options were going through and which weren't. You could even set up a final else-clause (not another else-if) that would let you know if none of the branches were being executed at all. In addition you could include the mouse button and mode into the display statement:
Display("before inv interactions. button: %d, mode: %d", button, mouse.Mode); and the like. The MouseButton values are as follows:
eMouseLeft = 1,
eMouseRight = 2,
eMouseMiddle = 3,
eMouseLeftInv = 5,
eMouseRightInv = 6,
eMouseWheelNorth = 8,
eMouseWheelSouth = 9
The value for mode would depend on your cursor layout, and should be relatively easy to discover from within the editor.
Sorry I can't be of more actual help, but I don't see any obvious mistakes.