OUYA detection?

Monkey Targets Forums/Ouya/OUYA detection?

Spinal(Posted 2013) [#1]
Just a quick question, Anyone know how, from Monkey, I can check if my android app is running on an OUYA, I think there is something in the ODK, but I have no idea how to use stuff like that from inside Monkey.
Also, anyone know how to uniquely identify an OUYA from within Monkey?

Thanks :)


Sensei(Posted 2013) [#2]
Do something like:

' At the top of your code set this variable, so it's easy to remember to change when you want to do a build test on the Ouya
#OUYA = "0"


#If OUYA = "1"
  ' Do Ouya specific stuff
#End

' To do Android specific stuff that won't affect Ouya
#If OUYA = "0"
   #If TARGET = "android"        
      DrawImage(buttonImage, posX, posY)
   #End
#End



This will let you do Ouya specific things like joypad control, text or graphical drawings etc.


Goodlookinguy(Posted 2013) [#3]
@Sensei
Monkey added True and False to the preprocessor in v76 (or 75?).

So that means you can do this now...
#OUYA = True
#If OUYA
	' do stuff
#End



Spinal(Posted 2013) [#4]
Thats fine and well, but whats to stop someone running my OUYA targeted game on any other android device?


AdamRedwoods(Posted 2013) [#5]
Thats fine and well, but whats to stop someone running my OUYA targeted game on any other android device?

Nothing SHOULD limit it from running on any other device. That's the beauty of Android, and the opposite of Apple.

You can always set device feature restrictions using the Manifest XML file (*recommended*):
http://developer.android.com/guide/topics/manifest/uses-feature-element.html

....but, here's what you probably want:
Extern
   Global ANDROID_PRODUCT:String = "android.os.Build.PRODUCT"
   Global ANDROID_MODEL:String = "android.os.Build.MODEL"
Public

''...etc...
Method OnCreate()
   Print ANDROID_PRODUCT
   Print ANDROID_MODEL
End



"model" returns better results, so you can just do a String.ToLower.Contains("ouya").


Sensei(Posted 2015) [#6]
I expect this won't be to everybody's liking, but I thought I'd share this here anyway, in case someone else might find this useful...

Since I am developing a game for multiple platforms, I've been trying to figure out a way to automate Monkey to be able to tell if you are building for Android or Ouya.
Because I import audio and graphics based on the target type, ie #If TARGET="html5", etc etc, using the above method that Adam provided wasn't going to work for me.

So instead I figured to do the following:
1. In the driver.monkey file located in {monkeyfolder}\modules\driver.monkey, I added "Or TARGET="ouya" at the end of the line:
#If TARGET="android" Or TARGET="flash" Or TARGET="glfw" Or TARGET="html5" Or TARGET="ios" Or TARGET="psm" Or TARGET="winrt" Or TARGET="xna" Or TARGET="ouya"
Import "native/mojo.${TARGET}.${LANG}"
#MOJO_DRIVER_IMPLEMENTED=True
#Endif

2. In {monkeyfolder}\modules\mojo\native\, I copied the mojo.android.java folder and renamed it to mojo.ouya.java
3. In the {monkeyfolder}\targets\android_ouya\TARGET.MONKEY file, I changed #TARGET_SYSTEM="android" to #TARGET_SYSTEM="ouya"

Now, in the game, I added this at the top after Import mojo:
#If TARGET = "ouya"
	#OUYA = True
#Else
	#OUYA = False
#End


Then anywhere in your game, when you need Android or Ouya specific imports or functionality, you could do as Goodlookingguy said:
#If OUYA
	' do stuff
#End


The main benefit of this method is that you never need to change a parameter by hand when you build for each platform, which you may forget to do until after you see the game running.

Apologies if people don't like this, but it works really well for me and I just wanted to share.