Difference between revisions of "Global Command: getProperty"
From The Official Visionaire Studio: Adventure Game Engine Wiki
(2 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
− | + | Get the requested game property. | |
− | |||
− | |||
− | |||
− | |||
− | |||
+ | {| class="ts" | ||
+ | |- | ||
+ | | style="width:15%" | Related functions | ||
+ | | [[Global Command: getGameClientAchievement|getGameClientAchievement]] | [[Global Command: getGameClientStat|getGameClientStat]] | [[Global Command: initGameClient|initGameClient]] | [[Global Command: resetGameClientStats|resetGameClientStats]] | [[Global Command: setGameClientAchievement|setGameClientAchievement]] | [[Global Command: setGameClientStat|setGameClientStat]] | ||
+ | |} | ||
− | |||
− | + | == Syntax == | |
− | Syntax | + | <syntaxhighlight lang="lua"> |
− | <syntaxhighlight> | + | getProperty(name) |
− | getProperty( | ||
</syntaxhighlight> | </syntaxhighlight> | ||
− | + | == Parameters == | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | + | {| class="ts" | |
− | + | |- | |
− | - | + | ! style="width:15%" | Parameter |
− | + | ! style="width:10%" | Type | |
+ | ! style="width:15%" | Supported values | ||
+ | ! Description | ||
+ | |- | ||
+ | | rowspan="6" | name | ||
+ | | rowspan="6" | string | ||
+ | | "platform" | ||
+ | | Identify the operating system the game is running on. | ||
+ | |- | ||
+ | | "steam_initialized" | ||
+ | | Check if the Steam API has been initialized. | ||
+ | |- | ||
+ | | "galaxy_initialized" | ||
+ | | Check if the GOG Galaxy API has been initialized. | ||
+ | |- | ||
+ | | "galaxy_ready" | ||
+ | | Check if the GOG Galaxy API is ready. | ||
+ | |- | ||
+ | | "system_language" | ||
+ | | Get the current operating system language. | ||
+ | |- | ||
+ | | "display_resolution" | ||
+ | | Detect which part of the window/screen the game takes up. | ||
+ | |} | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | + | == Return values == | |
− | |||
− | |||
− | |||
− | + | The return value depends on the passed "name" parameter: | |
− | |||
− | |||
− | |||
− | |||
− | |||
+ | {| class="ts" | ||
+ | |- | ||
+ | ! style="width:15%" | Passed parameter | ||
+ | ! style="width:15%" colspan="2" | Return type/structure | ||
+ | ! Description | ||
+ | |- | ||
+ | | "platform" | ||
+ | | colspan="2" | string | ||
+ | | Returns one of the following strings depending on the user's operating system: | ||
+ | * win | ||
+ | * mac | ||
+ | * ios | ||
+ | * android | ||
+ | * linux | ||
+ | * ps4 | ||
+ | * xbox1 | ||
+ | * html5 | ||
+ | |- | ||
+ | | "steam_initialized" | ||
+ | | colspan="2" | boolean | ||
+ | | Returns true if the Steam API was loaded and the client is connected. | ||
+ | |- | ||
+ | | "galaxy_initialized" | ||
+ | | colspan="2" | boolean | ||
+ | | Returns true if the GOG Galaxy API was loaded and the client is connected. | ||
+ | |- | ||
+ | | "galaxy_ready" | ||
+ | | colspan="2" | boolean | ||
+ | | Returns true if the GOG Galaxy API is ready. | ||
+ | |- | ||
+ | | "system_language" | ||
+ | | colspan="2" | string | ||
+ | | Returns the English name of the operating system language or "unknown" if the language couldn't be retrieved. | ||
+ | |- | ||
+ | | rowspan="4" | "display_resolution" | ||
+ | | rowspan="4" | t_rect | ||
+ | | x (int) | ||
+ | | rowspan="4" | Returns a Visionaire "t_rect" field: an associative array with the elements '''x''', '''y''', '''width''', and '''height''' holding the rectangle the game takes up in the game window or on the screen, respectively (optional black borders not included). | ||
+ | |- | ||
+ | | y (int) | ||
+ | |- | ||
+ | | width (int) | ||
+ | |- | ||
+ | | height (int) | ||
+ | |} | ||
− | + | == Examples == | |
− | + | '''Example 1:''' Do something depending on the user's operating system. | |
− | + | <syntaxhighlight lang="lua"> | |
− | + | local userPlatform = getProperty("platform") | |
− | |||
+ | if userPlatform == "win" or userPlatform == "mac" or userPlatform == "linux" then | ||
+ | print("We're on desktop.") | ||
+ | elseif userPlatform == "ios" or userPlatform == "android" then | ||
+ | print("This is mobile.") | ||
+ | elseif userPlatform == "ps4" or userPlatform == "xbox1" then | ||
+ | print("It's a console.") | ||
+ | elseif userPlatform == "html5" then | ||
+ | print("Browser is fine, too.") | ||
+ | end | ||
+ | </syntaxhighlight> | ||
− | |||
− | + | '''Example 2:''' Check if the Steam API has initialized and store the result in a (pre-defined) Visionaire condition called "steamInit". | |
+ | <syntaxhighlight lang="lua"> | ||
+ | local steamLoaded = getProperty("steam_initialized") | ||
+ | if steamLoaded then | ||
+ | Conditions["steamInit"].Value = true | ||
+ | else | ||
+ | Conditions["steamInit"].Value = false | ||
+ | end | ||
+ | </syntaxhighlight> | ||
− | |||
− | < | + | '''Example 3:''' Set the game language to the one we called "Deutsch" in our game settings, if the user's operating system is set to German. Set the game to English in all other cases. |
− | + | <syntaxhighlight lang="lua"> | |
+ | if getProperty("system_language") == "German" then | ||
+ | game.StandardLanguage = Languages["Deutsch"] | ||
+ | else | ||
+ | game.StandardLanguage = Languages["English"] | ||
+ | end | ||
+ | </syntaxhighlight> | ||
+ | {{toc}} |
Latest revision as of 12:06, 19 May 2023
Get the requested game property.
Related functions | getGameClientAchievement | getGameClientStat | initGameClient | resetGameClientStats | setGameClientAchievement | setGameClientStat |
Syntax
getProperty(name)
Parameters
Parameter | Type | Supported values | Description |
---|---|---|---|
name | string | "platform" | Identify the operating system the game is running on. |
"steam_initialized" | Check if the Steam API has been initialized. | ||
"galaxy_initialized" | Check if the GOG Galaxy API has been initialized. | ||
"galaxy_ready" | Check if the GOG Galaxy API is ready. | ||
"system_language" | Get the current operating system language. | ||
"display_resolution" | Detect which part of the window/screen the game takes up. |
Return values
The return value depends on the passed "name" parameter:
Passed parameter | Return type/structure | Description | |
---|---|---|---|
"platform" | string | Returns one of the following strings depending on the user's operating system:
| |
"steam_initialized" | boolean | Returns true if the Steam API was loaded and the client is connected. | |
"galaxy_initialized" | boolean | Returns true if the GOG Galaxy API was loaded and the client is connected. | |
"galaxy_ready" | boolean | Returns true if the GOG Galaxy API is ready. | |
"system_language" | string | Returns the English name of the operating system language or "unknown" if the language couldn't be retrieved. | |
"display_resolution" | t_rect | x (int) | Returns a Visionaire "t_rect" field: an associative array with the elements x, y, width, and height holding the rectangle the game takes up in the game window or on the screen, respectively (optional black borders not included). |
y (int) | |||
width (int) | |||
height (int) |
Examples
Example 1: Do something depending on the user's operating system.
local userPlatform = getProperty("platform")
if userPlatform == "win" or userPlatform == "mac" or userPlatform == "linux" then
print("We're on desktop.")
elseif userPlatform == "ios" or userPlatform == "android" then
print("This is mobile.")
elseif userPlatform == "ps4" or userPlatform == "xbox1" then
print("It's a console.")
elseif userPlatform == "html5" then
print("Browser is fine, too.")
end
Example 2: Check if the Steam API has initialized and store the result in a (pre-defined) Visionaire condition called "steamInit".
local steamLoaded = getProperty("steam_initialized")
if steamLoaded then
Conditions["steamInit"].Value = true
else
Conditions["steamInit"].Value = false
end
Example 3: Set the game language to the one we called "Deutsch" in our game settings, if the user's operating system is set to German. Set the game to English in all other cases.
if getProperty("system_language") == "German" then
game.StandardLanguage = Languages["Deutsch"]
else
game.StandardLanguage = Languages["English"]
end