@jayenkai - (U) menu button help needed!

Monkey Targets Forums/Ouya/@jayenkai - (U) menu button help needed!

Sensei(Posted 2014) [#1]
Hey Jayenkai (or anyone else that might know).

I am using the following code as an import in my game:
Import mojo.input

Class OuyaController
	Const OUYA_O:Int = JOY_A
	Const OUYA_U:Int = JOY_X
	Const OUYA_Y:Int = JOY_Y
	Const OUYA_A:Int = JOY_B
	
	Const OUYA_LB:Int = JOY_LB
	Const OUYA_RB:Int = JOY_RB
	Const OUYA_LSB:Int = JOY_LSB
	Const OUYA_RSB:Int = JOY_RSB
	
	Const OUYA_MENU:Int = JOY_MENU
	
	Const OUYA_DPAD_UP:Int = JOY_UP
	Const OUYA_DPAD_DOWN:Int = JOY_DOWN
	Const OUYA_DPAD_LEFT:Int = JOY_LEFT
	Const OUYA_DPAD_RIGHT:Int = JOY_RIGHT

	Function O:Int(port:Int=0)
		Return JoyDown(OUYA_O,port)
	End Function

	Function U:Int(port:Int=0)
		Return JoyDown(OUYA_U,port)
	End Function

	Function Y:Int(port:Int=0)
		Return JoyDown(OUYA_Y,port)
	End Function

	Function A:Int(port:Int=0)
		Return JoyDown(OUYA_A,port)
	End Function

	Function LeftBumper:Int(port:Int=0)
		Return JoyDown(OUYA_LB,port)
	End Function

	Function RightBumper:Int(port:Int=0)
		Return JoyDown(OUYA_RB,port)
	End Function

	Function DPadUp:Int(port:Int=0)
		Return JoyDown(OUYA_DPAD_UP,port)
	End Function

	Function DPadDown:Int(port:Int=0)
		Return JoyDown(OUYA_DPAD_DOWN,port)
	End Function

	Function DPadLeft:Int(port:Int=0)
		Return JoyDown(OUYA_DPAD_LEFT,port)
	End Function

	Function DPadRight:Int(port:Int=0)
		Return JoyDown(OUYA_DPAD_RIGHT,port)
	End Function

	Function LeftTrigger:Float(port:Int=0)
		Return JoyZ(0,port)
	End Function
		 
	Function LeftStickX:Float(port:Int=0)
		Local x:Float = JoyX(0,port)
		If x > 0 And x < 0.09 Then x = 0
		Return x
	End Function
		 
	Function LeftStickY:Float(port:Int=0)
		Local y:Float = JoyY(0,port)
		If y > 0 And y < 0.09 Then y = 0
		Return y
	End Function
		 
	Function LeftStickButton:Int(port:Int=0)
		Return JoyDown(OUYA_LSB,port)
	End Function
	
	Function RightTrigger:Float(port:Int=0)
		Return JoyZ(1,port)
	End Function
		 
	Function RightStickX:Float(port:Int=0)
		Local x:Float = JoyX(1,port)
		If x > 0 And x < 0.09 Then x = 0
		Return x
	End Function
		 
	Function RightStickY:Float(port:Int=0)
		Local y:Float = JoyY(1,port)
		If y > 0 And y < 0.09 Then y = 0
		Return y
	End Function
	
	Function RightStickButton:Int(port:Int=0)
		Return JoyDown(OUYA_RSB,port)
	End Function
	
	Function MenuButton:Int(port:Int=0)
		Return JoyDown(OUYA_MENU,port)
	End Function
	
	Function TouchpadButton:Int()
		Return TouchDown(0)
	End Function
	
	Function TouchpadX:Float()
		Return TouchX(0)
	End Function
	
	Function TouchpadY:Float()
		Return TouchY(0)
	End Function
	
End 


I forgot where I found it (somewhere on here I'm sure, so thanks to whomever wrote it!)

When looking at your games on the Ouya, Jeyenkai, I can see you do some sort of menu button capture. Upon first click, you go to the game menu, then in the menu if you push it again, it asks first if you are sure you want to quit. I like that and would like to do something similar, but as I've mentioned elsewhere in the past, when I push the menu button in my game, it goes to the menu as expected, but after a second or so, it quits completely out of the game.
Do I need to prevent or change the menu button state somehow to stop that from happening, or any help from you would be appreciated :)


Sensei(Posted 2014) [#2]
Nevermind. I figured it out. I was being daft and just doing stupid logic in the menu whereby I was immediately checking if the button state was quit then endapp. I've improved how I do it now and now you basically hold the button in for about 2 seconds before it quits, by way of timer countdown.

EDIT:
Actually, it seems to me the menu button state remains as if it's being pressed continually. If I push it the first time in the game state, it returns to the menu,but when I press O to start a new game, it goes back to the menu right away since the menu button state is still being reported as being pressed. If I press the menu button again, it's as if the button has now become unstuck. This is not something I have done, but menu button state changes.

Argh, why does this button have to be such a pain to use?

EDIT 2:
So, according to https://devs.ouya.tv/developers/docs/controllers I was right. It's an emulated press for both up and down states.


ElectricBoogaloo(Posted 2014) [#3]
Yes, menu button acts, not like a button, but like a toggle switch. I'm not sure why they made it like that, but.. Meh, whatever!

Apologies for late reply. If you need me, tell me on Twitter or something. I'm too busy writing AGameAWeek to keep track of all the hundreds of forums and things.


Sensei(Posted 2014) [#4]
Thanks matey.


computercoder(Posted 2015) [#5]
Wow. I just read this post.

@Sensei, this was my code. Glad you found it useful :)
I actually requested Mark to make the Home button work the way OUYA designed it to. I always thought that OUYA should have done something different than use a state. They also made the button terminate the app by double-tapping it.


Sensei(Posted 2015) [#6]
Thanks for letting me know matey. I need to credit you in my game for that code. ☺