problem with mouse management

Started by ranmyzer, Sat 03/09/2005 17:07:34

Previous topic - Next topic

ranmyzer

I can't set the right click events and left click events. I want that my adventure use the mouse in this mode:
right click -> look
left click -> everithing alse

this is my global script... where is the problem?

// main global script file
   DynamicSprite* dynArray[10];

#sectionstart game_start  // DO NOT EDIT OR REMOVE THIS LINE
function game_start() {
  // called when the game starts, before the first room is loaded
 
}
#sectionend game_start  // DO NOT EDIT OR REMOVE THIS LINE


#sectionstart repeatedly_execute  // DO NOT EDIT OR REMOVE THIS LINE
function repeatedly_execute() {
  // put anything you want to happen every game cycle here
}
#sectionend repeatedly_execute  // DO NOT EDIT OR REMOVE THIS LINE


function show_inventory_window () {
  // This demonstrates both types of inventory window - the first part is how to
  // show the built-in inventory window, the second part uses the custom one.
  // Un-comment one section or the other below.
 
  // ** DEFAULT INVENTORY WINDOW
//  InventoryScreen();

  // ** CUSTOM INVENTORY WINDOW
  gInventory.Visible = true;
  // switch to the Use cursor (to select items with)
  mouse.Mode = eModeInteract;
  // But, override the appearance to look like the arrow
  mouse.UseModeGraphic(eModePointer);

}

#sectionstart on_key_press  // DO NOT EDIT OR REMOVE THIS LINE
function on_key_press(int keycode) {
  // called when a key is pressed. keycode holds the key's ASCII code
  if (IsGamePaused() == 1) keycode=0;  // game paused, so don't react to keypresses
  if (keycode==17)  QuitGame(1);   // Ctrl-Q
  if (keycode==363) SaveGameDialog();   // F5
  if (keycode==365) RestoreGameDialog();  // F7
  if (keycode==367) RestartGame();  // F9
  if (keycode==434) SaveScreenShot("scrnshot.bmp");  // F12
  if (keycode==9)   show_inventory_window();  // Tab, show inventory

  if (keycode==19)  Debug(0,0);  // Ctrl-S, give all inventory
  if (keycode==22)  Debug(1,0);  // Ctrl-V, version
  if (keycode==1)   Debug(2,0);  // Ctrl-A, show walkable areas
  if (keycode==24)  Debug(3,0);  // Ctrl-X, teleport to room
}
#sectionend on_key_press  // DO NOT EDIT OR REMOVE THIS LINE


#sectionstart on_mouse_click  // DO NOT EDIT OR REMOVE THIS LINE
function on_mouse_click(MouseButton button) {


  if (IsGamePaused()) {

  }
  if (Hotspot.GetAtScreenXY(mouse.x, mouse.y) == hotspot[0]) {
  ProcessClick(mouse.x, mouse.y, MODE_WALK);
  }
  else if (button == eMouseLeft) {
  ProcessClick(mouse.x, mouse.y, MODE_USE);
  }
  else if (button == eMouseRight) {
  ProcessClick(mouse.x, mouse.y, MODE_LOOK);
  }
  else if (button == eMouseLeftInv){
    ProcessClick(mouse.x, mouse.y, eModeInteract);
  }
  else if (button == eMouseRightInv){
    ProcessClick(mouse.x,  mouse.y, eModeLookat);
  }
  }
#sectionend on_mouse_click  // DO NOT EDIT OR REMOVE THIS LINE


#sectionstart interface_click  // DO NOT EDIT OR REMOVE THIS LINE
function interface_click(int interface, int button) {
}
#sectionend interface_click  // DO NOT EDIT OR REMOVE THIS LINE



#sectionstart btnInvOK_Click  // DO NOT EDIT OR REMOVE THIS LINE
function btnInvOK_Click(GUIControl *control, MouseButton button) {
 
   // They pressed the OK button, close the GUI
   gInventory.Visible = false;
   mouse.UseDefaultGraphic();
}
#sectionend btnInvOK_Click  // DO NOT EDIT OR REMOVE THIS LINE

#sectionstart btnInvSelect_Click  // DO NOT EDIT OR REMOVE THIS LINE
function btnInvSelect_Click(GUIControl *control, MouseButton button) {
 
   // They pressed SELECT, so switch to the Get cursor
   mouse.Mode = eModeInteract;
   // But, override the appearance to look like the arrow
   mouse.UseModeGraphic(eModePointer);
}
#sectionend btnInvSelect_Click  // DO NOT EDIT OR REMOVE THIS LINE

#sectionstart btnIconInv_Click  // DO NOT EDIT OR REMOVE THIS LINE
function btnIconInv_Click(GUIControl *control, MouseButton button) {
 
  show_inventory_window();
}
#sectionend btnIconInv_Click  // DO NOT EDIT OR REMOVE THIS LINE

#sectionstart btnIconCurInv_Click  // DO NOT EDIT OR REMOVE THIS LINE
function btnIconCurInv_Click(GUIControl *control, MouseButton button) {
 
  if (player.ActiveInventory != null)
    mouse.Mode = eModeUseinv;
}
#sectionend btnIconCurInv_Click  // DO NOT EDIT OR REMOVE THIS LINE

#sectionstart btnIconLoad_Click  // DO NOT EDIT OR REMOVE THIS LINE
function btnIconLoad_Click(GUIControl *control, MouseButton button) {
 
  RestoreGameDialog();
}
#sectionend btnIconLoad_Click  // DO NOT EDIT OR REMOVE THIS LINE

#sectionstart btnIconExit_Click  // DO NOT EDIT OR REMOVE THIS LINE
function btnIconExit_Click(GUIControl *control, MouseButton button) {
 
  QuitGame(1);
}
#sectionend btnIconExit_Click  // DO NOT EDIT OR REMOVE THIS LINE

#sectionstart btnIconAbout_Click  // DO NOT EDIT OR REMOVE THIS LINE
function btnIconAbout_Click(GUIControl *control, MouseButton button) {
 
  Display("Adventure Game Studio v2 run-time engine[[Copyright (c) 1999-2005 Chris Jones");
}
#sectionend btnIconAbout_Click  // DO NOT EDIT OR REMOVE THIS LINE


#sectionstart Conferma_Click  // DO NOT EDIT OR REMOVE THIS LINE
function Conferma_Click(GUIControl *control, MouseButton button) {
   int i = 0;
   while(i<10) {
      if(dynArray != null)
      {
      dynArray.Delete();
      }
   i++;
   }
  gSavegui.Visible = false;
   gGui4.Visible = false;
   Wait(1);
   SaveGameSlot(100,"descrizione");

}
#sectionend Conferma_Click  // DO NOT EDIT OR REMOVE THIS LINE

#sectionstart btnIconSave_Click  // DO NOT EDIT OR REMOVE THIS LINE
function btnIconSave_Click(GUIControl *control, MouseButton button) {
   int width = 120;
   int height = 90;
   int i = 0;
   while(i<10)
   {
      dynArray = DynamicSprite.CreateFromSaveGame(100+i,width,height);
      i++;
   }
   if(dynArray[0] != null)
      button0.NormalGraphic = dynArray[0].Graphic;
   gSavegui.Visible = true;
}
#sectionend btnIconSave_Click  // DO NOT EDIT OR REMOVE THIS LINE

#sectionstart button0_Click  // DO NOT EDIT OR REMOVE THIS LINE
function button0_Click(GUIControl *control, MouseButton button) {
  gGui4.Centre();
  gGui4.Visible = true;
}
#sectionend button0_Click  // DO NOT EDIT OR REMOVE THIS LINE

Ashen

What exactly is the problem -  what is/isn't it doing that's wrong? (Running wrong interactions, not running any interactions, game not starting, etc)

Two things I've spotted:

   Since you're using 2.7, you'll need to change the 3 MODE_XXX's in the on_mouse_click section to eModeXXX (like you have for eMouseLeft/RightInv). I can't even get it to compile using MODE_XXX.

   Also in on_mouse_click, try changing:
Code: ags

 if (Hotspot.GetAtScreenXY(mouse.x, mouse.y) == hotspot[0]) {
  ProcessClick(mouse.x, mouse.y, MODE_WALK);
  }

  to:
Code: ags

 if (GetLocationType(mouse.x, mouse.y) == eLocationNothing) {
  ProcessClick(mouse.x, mouse.y, MODE_WALK);
 }

As it is, I think it'll only run the Look at/Use interactions if it's over a Hotspot (HotspotAt(mouse.x, mouse.y) != hotspot[0]) and not just a Character or Object.

But they might not be the problem...
I know what you're thinking ... Don't think that.

ranmyzer

tnx a lot for the reply!

i've changed the code with that but i've not resolved. (i have the 2.7 version)

the problem: look click it's ok but the right click mouse is death.

Ashen

I thought Right Click was look? By 'right click mouse is death', I take it you mean the game crashes - is there an error message? I've made a test game using the (modified) on_mouse_click code from above and it works fine, so the script should be sound.

Does it matter where you click (an Object, a Character, empty screen), or does it always do the same thing? What's the Look at/Interact script for wherever you're clicking - it could be that that's causing the problem.
I know what you're thinking ... Don't think that.

ranmyzer

the game don't crash, but when i click in the left mouse button ags ignore my command.

if you can this is the link of the game folder.

http://ranmyzer.altervista.org/Interf_ok.rar


Ashen

1. You're still using the original on_mouse_click code, not the modified version. That's not a problem in this little test game, but might start to be when you add more to it - since, as I said, it won't register clicks on characters or objects. I think:
Code: ags

 if (GetLocationType(mouse.x,mouse.y) == eLocationNothing && GUI.GetAtScreenXY(mouse.x,mouse.y) != gInventory) {
  ProcessClick(mouse.x, mouse.y, eModeWalkto);
 }

should work OK, and stop you walking into the Inventory, but maybe someone knows a better way?

2. Left clicking the Stickman hotspot works fine, for me. Right clicking causes a crash, since you tried to display an 'è', which AGS can't do by default (and should've given an error message). You need to import a font that can handle extended characters (most ttf fonts do).

3. Left clicking the Inventory items doesn't do anything - is that what you meant? You'll need to check the Handle Inventory clicks in script box on the 'General Settings' window of the editor. Also, you might have to change the eMouseLeft/RightInv bits of your on_mouse_click to:
Code: ags

  else if (button == eMouseLeftInv){
    inventory[game.inv_activated].RunInteraction(eModeInteract);

  }
  else if (button == eMouseRightInv){
    inventory[game.inv_activated].RunInteraction(eModeLookat);
  }


I know what you're thinking ... Don't think that.

monkey0506

Quote from: Ashen on Mon 05/09/2005 11:13:01Also, you might have to change the eMouseLeft/RightInv bits of your on_mouse_click to:
Code: ags

  else if (button == eMouseLeftInv){
    inventory[game.inv_activated].RunInteraction(eModeInteract);

  }
  else if (button == eMouseRightInv){
    inventory[game.inv_activated].RunInteraction(eModeLookat);
  }




I believe that game.inv_activated has been deprecated and as of version 2.7 is player.ActiveInventory.  So maybe:

Code: ags
  else if (button == eMouseLeftInv) {
    inventory[player.ActiveInventory.ID].RunInteraction(eModeInteract);
    }
  else if (button == eMouseRightInv) {
    inventory[player.ActiveInventory.ID].RunInteraction(eModeLookat);
    }


Would be more 2.7 appropriate.  Notice that I used player.ActiveInventory.ID to access the inventory array, because the ActiveInventory property is an InventoryItem*, not an int.  The ID property is the integer value of the item.

SSH

Quote from: monkey_05_06 on Mon 05/09/2005 11:25:14
Code: ags
  else if (button == eMouseLeftInv) {
    inventory[player.ActiveInventory.ID].RunInteraction(eModeInteract);
    }
  else if (button == eMouseRightInv) {
    inventory[player.ActiveInventory.ID].RunInteraction(eModeLookat);
    }


Why not just:

Code: ags

else if (button == eMouseLeftInv) {
    player.ActiveInventory.RunInteraction(eModeInteract);
    }
  else if (button == eMouseRightInv) {
    player.ActiveInventory.RunInteraction(eModeLookat);
    }


12

Ashen

(Just to confuse things even more for ranmyzer...)

Quote from: monkey_05_06
I believe that game.inv_activated has been deprecated ... as of version 2.7

Well .....
Code: ags

if (button == eMouseLeftInv)
    inventory[game.inv_activated].RunInteraction(mouse.Mode);

is the sample code for RunInteraction (inventory)  in the 2.7 manual, and works fine for me - although I haven't kept up with the latest 2.71 (& betas), so it might have changed by now. But yes, your way (actually SSH's simplified way) would probably be better practice.
I know what you're thinking ... Don't think that.

monkey0506

Because SSH, I didn't think about the fact that the inventory array is also an array of InventoryItem*s, so it contains the same functions as player.ActiveInventory, so you could do that...but yes, that would make more sense to do it that way.

ranmyzer

Tnx a lot to everybody for the help. This evening i'v try to set your suggestions.

I will give you the link of the new folder.





Pumaman

Quote from: monkey_05_06 on Mon 05/09/2005 11:25:14
I believe that game.inv_activated has been deprecated and as of version 2.7 is player.ActiveInventory. So maybe:

No, these are NOT the same.

game.inv_activated tells you which inventory item was clicked on, if you have the inventory window open and look at an item, for example.

player.ActiveInventory is the character's current active inventory item.

So, player.ActiveInventory is which item you used, whereas game.inv_activated is the item that you used it on.

SSH

Just to claify, though, the on_click function for the inventory will have "this" pointer set so that this.ID == game.inv_activated? True?
12

Pumaman

If you mean the inventory GUI's on_click function then no, since there is no "this" pointer. In fact, no built-in features use a "this" pointer, that's only available in custom structs.

monkey0506

Quote from: Pumaman on Mon 05/09/2005 19:44:23
Quote from: monkey_05_06 on Mon 05/09/2005 11:25:14
I believe that game.inv_activated has been deprecated and as of version 2.7 is player.ActiveInventory. So maybe:

No, these are NOT the same.

game.inv_activated tells you which inventory item was clicked on, if you have the inventory window open and look at an item, for example.

player.ActiveInventory is the character's current active inventory item.

So, player.ActiveInventory is which item you used, whereas game.inv_activated is the item that you used it on.


My mistake. :-[  Sorry.

ranmyzer

WOW... Work fine!!! Tnx to Ashen's code and everybody for the help.

Ranmyzer.

SMF spam blocked by CleanTalk