Workaround for mouse wheel select next and previous mouse mode?

Started by Husky, Fri 23/06/2006 00:52:30

Previous topic - Next topic

Husky

I'm stumped on how to get the middle mouse wheel to select both the next and previous mouse modes.Ã,  I know that Select Previous Mouse Mode is currently unsupported.Ã,  However, I've been unsuccessfully trying to script a workaround.Ã,  Here is what I have so far (please note, I have no programming background, except for studying the AGS manual and reading past posts, so if I've made obvious mistakes, know I'm diligently working to improve.):

Code: ags

function on_mouse_click(MouseButton button) {
Ã,  // called when a mouse button is clicked. button is either LEFT or RIGHT
Ã,  if (IsGamePaused() == 1) {
Ã,  // Game is paused, so do nothing (ie. don't allow mouse click)
	}
		else if (button == eMouseLeft) {
			ProcessClick(mouse.x, mouse.y, mouse.Mode );
Ã,  Ã,  }
		else if (button == eMouseRight || eMouseMiddle || eMouseWheelSouth) {
			//Any of these mouse events trigger Select Next Mouse Mode
			mouse.SelectNextMode();
Ã,  Ã,  }
		else if (button == eMouseWheelNorth) { 
			// simulate "Mouse Select Previous Mode" which is currently unsupported
			if (mouse.Mode == eModeUseinv)
			mouse.Mode == eModeInteract;
			else if (mouse.Mode == eModeInteract)
			mouse.Mode == eModeLookat;
			else if (mouse.Mode == eModeLookat)
			mouse.Mode == eModeWalkto;
			else if (mouse.Mode == eModeWalkto && (cCharacter.ActiveInventory != null)
			mouse.Mode == eModeUseinv;
			// player has inventory item active so go to Useinv
			else if (mouse.Mode == eModeWalkto && (cCharacter.ActiveInventory == null)
			mouse.Mode == eModeUseinv;
			// player has no active inventory item so skip to Talkto
		}
}


If any of you programming gurus have any advice for me, I'd greatly appreciate it.Ã,  Thanks in advance.

GarageGothic

It looks more or less ok, what are you having problems with specifically?

There are a few things though. First of all you've put eModeUseinv in the last line where it, according to your comment,  should be eModeTalkto. However, there seems to be no way to get to eModeTalkto if you DO have a inventory item seleted - if so it skips directly to eModeInteract. Also, depending on your game design, you should take into consideration that not all cursor modes are always available (such as Walkto missing in first person views etc.).

edit: updated code, not tested :
Code: ags

function on_mouse_click(MouseButton button) {
  // called when a mouse button is clicked. button is either LEFT or RIGHT
  if (IsGamePaused() == 1) {
  // Game is paused, so do nothing (ie. don't allow mouse click)
	}
		else if (button == eMouseLeft) {
			ProcessClick(mouse.x, mouse.y, mouse.Mode );
    }
		else if (button == eMouseRight || eMouseMiddle || eMouseWheelSouth) {
			//Any of these mouse events trigger Select Next Mouse Mode
			mouse.SelectNextMode();
    }
		else if (button == eMouseWheelNorth) { 
			// simulate "Mouse Select Previous Mode" which is currently unsupported
			if (mouse.Mode == eModeUseinv)
                        mouse.Mode == eModeTalkto;
                        else if (mouse.Mode == eModeTalkto)
			mouse.Mode == eModeInteract;
			else if (mouse.Mode == eModeInteract)
			mouse.Mode == eModeLookat;
			else if (mouse.Mode == eModeLookat)
			mouse.Mode == eModeWalkto;
			else if (mouse.Mode == eModeWalkto && (cCharacter.ActiveInventory != null)
			mouse.Mode == eModeUseinv;
			// player has inventory item active so go to Useinv
			else if (mouse.Mode == eModeWalkto && (cCharacter.ActiveInventory == null)
			mouse.Mode == eModeTalkto;
			// player has no active inventory item so skip to Talkto
		}
}

Husky

Thank you for the reply, GarageGothic.Ã,  First, you made a good correction to the final line of code, my error.Ã,  Second, you bring up a good point that all cursor modes are not always available in a game.Ã,  I'll need to tackle that next.Ã,  But for now, I think my specific problem is getting eMouseWheelNorth and eMouseWheelSouth to work, period.Ã, 

I've put together this little test to try and isolate the problem.Ã,  In the test, eMouseRight, eMouseMiddle, and eMouseWheelSouth should advance the Mouse Mode.Ã,  eMouseWheelNorth should display “Horray, I work!"Ã,  Unfortunately, the results of this test are, eMouseWheelSouth and eMouseWheelNorth do absolutely nothing, yet the left and right mouse buttons act properly.

Code: ags

function on_mouse_click(MouseButton button) {
Ã,  // called when a mouse button is clicked. button is either LEFT or RIGHT
Ã,  if (IsGamePaused() == 1) {
Ã,  Ã,  // Game is paused, so do nothing (ie. don't allow mouse click)
	}
		else if (button == eMouseLeft) {
Ã,  Ã,  ProcessClick(mouse.x, mouse.y, mouse.Mode );
Ã,  Ã,  }
		else if (button == eMouseRight || eMouseMiddle || eMouseWheelSouth) {
Ã,  Ã,  mouse.SelectNextMode();
Ã,  Ã,  }
		else if (button == eMouseWheelNorth) {
		Display("Horray, I work!");
		}
}


I need to figure out how to get some sort of response from the mouse wheel.Ã,  Thoughts?

GarageGothic

EDIT: I feel slightly embarassed asking this, but you DID activate "Enable mouse wheel support" in the General settings page of the editor, right?


Ok, I think the problem is the line:
Code: ags
else if (button == eMouseRight || eMouseMiddle || eMouseWheelSouth)


I'm not sure the or (||) conditional can be used like that. Try to put instead:

Code: ags
else if ((button == eMouseRight) || (button == eMouseMiddle) || (button == eMouseWheelSouth))


And see if that works better. I suppose this line for some reason always registers as true, so the script doesn't get to the MouseWheelNorth section.

Husky

Brilliant!Ã,  First, I did not activate "Enable mouse wheel support.”Ã,  Ã, And yes, I feel embarrassed admitting that.Ã,  Second, you were correct about adding the extra brackets to the code â€" they were needed.Ã,  Finally, I made a few minor corrections.Ã,  Now it works perfectly.Ã,  The mouse wheel is now able to switch the modes both forward AND backward.Ã,  Thank you, GarageGothic.Ã,  For the record, here is the final working code with corrections.

Code: ags

function on_mouse_click(MouseButton button) {
Ã,  // called when a mouse button is clicked.
Ã,  if (IsGamePaused() == 1) {
Ã,  Ã,  // Game is paused, so do nothing (ie. don't allow mouse click)
}
else if (button == eMouseLeft) {
Ã,  Ã,  ProcessClick(mouse.x, mouse.y, mouse.Mode );
Ã,  Ã,  }
else if ((button == eMouseRight) || (button == eMouseMiddle) || (button == eMouseWheelSouth)) {
Ã,  Ã,  mouse.SelectNextMode();
Ã,  Ã,  }
else if (button == eMouseWheelNorth) {
// simulate "Mouse Select Previous Mode" which is currently unsupported
	Ã,  if (mouse.Mode == eModeUseinv)
		Ã,  Ã,  mouse.Mode = eModeTalkto;
	Ã,  else if (mouse.Mode == eModeTalkto)
		Ã,  Ã,  mouse.Mode = eModeInteract;
	Ã,  else if (mouse.Mode == eModeInteract)
		Ã,  Ã,  mouse.Mode = eModeLookat;
	Ã,  else if (mouse.Mode == eModeLookat)
		Ã,  Ã,  mouse.Mode = eModeWalkto;
	Ã,  else if ((mouse.Mode == eModeWalkto) && (player.ActiveInventory != null))
		Ã,  Ã,  mouse.Mode = eModeUseinv;
// player has inventory item active so go to Useinv
	Ã,  else if ((mouse.Mode == eModeWalkto) && (player.ActiveInventory == null))
		Ã,  Ã,  mouse.Mode = eModeTalkto;
// player has no active inventory item so skip to Talkto
	}
}

Khris

Just a minor addition(?):
It's clear that if (button==a || b || c) was wrong. This condition is always true because b!=0 (and c!=0, too).
But it's not necessary to use brackets, if (button==a || button==b || button==c) should work fine.

Husky

Thanks for the additional input, KhrisMUC.

Before this thread is closed as solved, I'm just curious, if anyone has an opinion on an issue of style.Ã,  Is it more intuitive to use eMouseWheelSouth to select the next mouse mode and eMouseWheelNorth to select the previous mouse mode?Ã,  Or should it be the opposite?Ã,  I'm experimenting with both, and they both seem fine to me.Ã,  However, if there is a convention or a general preference, I'd love to know so I don't annoy everyone by getting it backwards in the game.

Thanks again.

Khris

There's no convention, it's completely up to the designer, but I believe many Egoshooters use down to select the next weapon (& up to select the previous). It might be the other way round, though, 'cause I almost always turn it in the wrong direction at first :)

There were one or two AGS games who used this, and I was irritated quite a bit by having to scroll up to select the next mode.
And you'd scroll down to see the next page of e.g. a PDF, so using MouseWheelSouth to select the next mode is more natural, IMO.

Husky

Good points, KhrisMUC.Ã,  I will use eMouseWheelSouth to select the next mouse mode and eMouseWheelNorth select the previous mouse mode.Ã,  Thank you.

GarageGothic

I actually added a checkbox in the options menu in my game to switch the direction. I felt it more natural that up meant forward, but as KrishMUC says, down is commonly used to advance to next page (sensible since that makes left-right page flipping analogous to scrolling a webpage). It's VERY easy to add this as a user option, so I suggest you do that if at all in doubt. At the beginning of the mouseclick function, just put:

Code: ags
if ((button == eMouseWheelNorth) && (reversescroll == 1)) button = eMouseWheelSouth;
else if ((button == eMouseWheelSount) && (reversescroll == 1)) button = eMouseWheelNorth;


This assumes a global int called reversescroll

Husky

Excellent idea, GarageGothic.Ã,  A "switch the direction" scroll option does seem in order.Ã,  Thank you.

SMF spam blocked by CleanTalk