Simple platform check

Monkey Forums/Monkey Code/Simple platform check

EdzUp(Posted 2013) [#1]
I know there are probably more 'elegant' and efficient ways of doing it but this has proven helpful to me over the last couple of weeks. Just thought it might help someone else :)

Global Platform:Int =0
Const Platform_Mobile = 1
Const Platform_Internet = -1
Const Platform_Desktop = 0

Function CheckPlatform:Int()
	Platform =Platform_Desktop
	#If TARGET="android" Or TARGET="ios" Or TARGET="winphone8"
		Platform = Platform_Mobile		'mobile
	#Else
		#If TARGET="html5" Or TARGET="flash" Or TARGET="java"
			Platform =Platform_Internet		'internet
		#Endif
	#Endif
	
	Return( Platform )
End


Basically call CheckPlatform() at the beginning of OnCreate and then you can check the Platform variable against the constants to see what you are currently running on be it either mobile, internet or desktop platforms :)


therevills(Posted 2013) [#2]
Why don't you use your constants?

Const PLATFORM_DESKTOP:Int = 0
Const PLATFORM_MOBILE:Int = 1
Const PLATFORM_INTERNET:Int = 2

Function CheckPlatform:Int()
	local platform:Int = PLATFORM_DESKTOP
	#If TARGET="android" Or TARGET="ios"
		platform = PLATFORM_MOBILE		'mobile
	#Else
		#If TARGET="html5" Or TARGET="flash"
			platform = PLATFORM_INTERNET		'internet
		#Endif
	#Endif
	
	Return platform
End



EdzUp(Posted 2013) [#3]
Yeah did see that :) fixed it :)


EdzUp(Posted 2013) [#4]
Added support for windows phone 8 and windows 8 stuffs :)


ziggy(Posted 2013) [#5]
That's helpful!
Shouldn't the metro apps be considered Mobile?