Detecting the current OS information for selective code. Sometimes you want to enable or disable code, or have dummy simulated code go off depending on which platform you are testing.
Is there a list of all current possibilities somewhere? Can someone check what the Linux one is?
local sysinfo = sys.get_sys_info()
if sysinfo.system_name == “Android” then
…
elseif sysinfo.system_name == “iPhone OS” then
…
elseif sysinfo.system_name == “Windows” then
…
elseif sysinfo.system_name == “Linux” then
…
elseif sysinfo.system_name == “Darwin” then – This means it’s a Mac OSX build
…
elseif sysinfo.system_name == “HTML5” then
…
end
If you are targeting iOS / Android you can get more specific information with device_model and manufacturer, which can be useful.
You can detect browser for HTML builds by parsing the information provided by user_agent.
local sysinfo = sys.get_sys_info()
if sysinfo.system_name == “HTML” then
local user_agent = sysinfo.user_agent
…
end
As far as I can tell, there is currently no (easy) way to detect different versions of Window, Linux or Max OS X.
Detecting device language can be done in the same way. If you are planning to localize your game to ship with many translations you’ll want to
When you setup your localization you can look up the ISO codes for the languages you support, and if on the first start the device is a language you support you could default to it.
local sysinfo = sys.get_sys_info()
if sysinfo.device_language == “en” then
…