handle right click but not left

Started by YotamElal, Mon 07/03/2005 16:12:24

Previous topic - Next topic

YotamElal

I set HandleInventoryClicks to 1,
so I can have a right button that cycles instead of looks.

I want the left button to work like it does as defualt.

Can I set HandleInventoryClicks only for right button,
Or can anyone post the script for the left button
(as if it was handled automatically)

??

strazer

It think the example code for RunInventoryInteraction in the help file is what you're looking for.

YotamElal

This is the example code in the help file.
I am currently using it.

if (button == LEFTINV)
  RunInventoryInteraction(game.inv_activated, GetCursorMode());


It does not  let me look at an inv item.
It does not  let me use an inv item with another inv item.
:o(



strazer

It should work fine.
Have you put it in your on_mouse_click function?
Do you have a Look interaction defined for the inv item you're testing it with?
Do other cursor modes work?

Maybe there is a braces problem. Please post your whole on_mouse_click function.
Use the [ code ] tag (without spaces):

[ code ]
This is some script
[ /code ]

becomes

Code: ags

This is some script

YotamElal

when I try to look at an inv item or use an inv item with another one,
the item gets picked up.
:o(


Code: ags

function on_mouse_click(int button) {
  if (IsGamePaused() == 1) {}
  else if (button==LEFT) { ProcessClick(mouse.x, mouse.y, GetCursorMode() ); }
  else if (button == LEFTINV) { SetActiveInventory(game.inv_activated);}
  else if (button == RIGHTINV) {
    DisableCursorMode(MODE_WALK);
    SetNextCursorMode();
    EnableCursorMode(MODE_WALK);
  }
  else {   // right-click, so cycle cursor
    SetNextCursorMode();
  }
}

strazer

I don't quite understand:

Quote
This is the example code in the help file.
I am currently using it.

Yet in your on_mouse_click function you have

Code: ags

  else if (button == LEFTINV) { SetActiveInventory(game.inv_activated);}


This obviously selects the item you clicked on, not running its interaction.

What happens if you replace
  SetActiveInventory(game.inv_activated);
with
  RunInventoryInteraction(game.inv_activated, GetCursorMode());
?

Scorpiorus

Ah, think I got what you're after.

Unless I forgot something, here is a code for handling inv items clicks that works exactly as the built-in mechanism:

if    (button==LEFTINV) // left click on inventory item:
{
   if (GetCursorMode()==MODE_USE)
   {   
      // select inventory on MODE_USE:
      SetActiveInventory(game.inv_activated);
   }
   else
   {
      // run other interaction if the cursor mode isn't MODE_USE:
      RunInventoryInteraction(game.inv_activated, GetCursorMode());
   }
}
else if (button==RIGHTINV) // right click on inventory item:
{
   // always run look interaction on MODE_LOOK:
   RunInventoryInteraction(game.inv_activated, MODE_LOOK);
}

You may probably want to replace the code under "if (button==RIGHTINV)" clause with "SetNextCursorMode();" to suit your needs.

Keep in mind, however, to deselect the active inventory item you need a separate GUI button with the following code:

SetActiveInventory(-1); // deselect the current active inv
SetCursorMode(MODE_USE); // back to the Use mode

Let us know if that is it, otherwise please elaborate a bit on what you are after.

YotamElal

scorpiorus:
PERFECT!!!!!!!!!!!!!!!!!!!

but I didn't understande why you wrote this??

Quote
Keep in mind, however, to deselect the active inventory item you need a separate GUI button with the following code:

SetActiveInventory(-1); // deselect the current active inv
SetCursorMode(MODE_USE); // back to the Use mode



strazer: RunInventoryInteraction(game.inv_activated, GetCursorMode());
              Doesn't pickup at all...

strazer

Quotestrazer: RunInventoryInteraction(game.inv_activated, GetCursorMode());
              Doesn't pickup at all...

Yeah, it doesn't work since there's no cursor mode that by default selects items, so you have to use the script as shown by Scorpiorus. Sorry for the confusion.

Scorpiorus

Quote from: YotamElal on Wed 09/03/2005 04:47:45but I didn't understande why you wrote this??

Quote
Keep in mind, however, to deselect the active inventory item you need a separate GUI button with the following code:

SetActiveInventory(-1); // deselect the current active inv
SetCursorMode(MODE_USE); // back to the Use mode
I mentioned it just in case. The thing is, there is no way for the code I posted (and also that's how the default inventory handling mechanism works) to deselect an active item and restore the USE mode back, because there is no way to change the current cursor mode. That's why there is an arrow-looking button on the default inventory GUI.
It shouldn't be a problem considering the modification you are making (SetNextCursorMode), because that will allow cycling to the USE mode so that one could select other inventory item as the active one.
However, I'd introduce a way to quickly deselect an item since one may find it annoying to have to cycle to the USE mode, just to be able to select another item.
It could probably be that GUI button similar to the default inventory GUI.
Alternatively, you can add an extra code for RIGHTINV so that it would reset an active item and set the USE mode the first time the right mouse button is clicked and then it would do cycling as usual:

else if (button==RIGHTINV) // right click on inventory item:
{
   // if there is active inventory item
   if (character[GetPlayerCharacter()].activeinv != -1)
   {
      SetActiveInventory(-1); // deselect the current active inv
      SetCursorMode(MODE_USE); // back to the Use mode
   }
   else
   {
      SetNextCursorMode(); // cycle further
   }
}

Just an idea...

SMF spam blocked by CleanTalk