Difference between revisions of "Global Command: getProperty"

From The Official Visionaire Studio: Adventure Game Engine Wiki
(Created page with "<div class="toccolours mw-collapsible mw-collapsed tbl-ds"> <span class="bold">Command History</span> <div class="mw-collapsible-content"> <div class="alt-bg">Available since ...")
 
 
(6 intermediate revisions by 3 users not shown)
Line 1: Line 1:
<div class="toccolours mw-collapsible mw-collapsed tbl-ds">
+
Get the requested game property.
<span class="bold">Command History</span>
 
<div class="mw-collapsible-content">
 
<div class="alt-bg">Available since v3.7</div>
 
<div>system_language property added to v3.8</div>
 
</div></div>
 
  
 +
{| 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]]
 +
|}
  
Return the requested property.
 
  
 
+
== Syntax ==
Syntax:
+
<syntaxhighlight lang="lua">
<syntaxhighlight>
+
getProperty(name)
getProperty(property)
 
 
</syntaxhighlight>
 
</syntaxhighlight>
  
  
Example 1: "platform"
+
== Parameters ==
<syntaxhighlight>
 
-- if platform equals windows then do some action else if mac do some other action!
 
if getProperty("platform") == "win" then
 
getObject("Conditions[win?]"):setValue(VConditionValue, true)
 
elseif getProperty("platform") == "mac" then
 
getObject("Conditions[mac?]"):setValue(VConditionValue, true)
 
end
 
</syntaxhighlight>
 
  
Example 2: "steam_initialized"
+
{| class="ts"
<syntaxhighlight>
+
|-
-- let's check if steam has initialized & set a value based on return value!
+
! style="width:15%" | Parameter
local steamLoaded == getProperty("steam_initialized")
+
! 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.
 +
|}
  
if steamLoaded then
 
getObject("Conditions[steamLoaded?]"):setValue(VConditionValue, true)
 
else
 
getObject("Conditions[steamLoaded?]"):setValue(VConditionValue, false)
 
end
 
</syntaxhighlight>
 
  
Example 3: "system_language"
+
== Return values ==
<syntaxhighlight>
 
-- let's check the current users operating system language & store it in a variable!
 
local sysLang == getProperty("system_language")
 
  
if sysLang == "English" then
+
The return value depends on the passed "name" parameter:
game:setValue(VGameStandardLanguage, getObject("Languages[English]"))
 
elseif sysLang == "German" then
 
game:setValue(VGameStandardLanguage, getObject("Languages[Deutsch]"))
 
end
 
</syntaxhighlight>
 
  
 +
{| 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)
 +
|}
  
  
<span class="bold underline">Arguments</span>
+
== Examples ==
  
<span class="bold">property</span>: "string" <br/>
+
'''Example 1:''' Do something depending on the user's operating system.
* "platform" (returns "win" or "mac" depending on users operating system)
+
<syntaxhighlight lang="lua">
* "steam_initialized" (true/false depending if the steam_api is successfully loaded & client is connected)
+
local userPlatform = getProperty("platform")
* "system_language" (returns users system language in english; english, german, spanish etc)
 
  
 +
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>
  
<span class="bold underline">Flags</span>
 
  
none
+
'''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>
  
<span class="bold underline">Return</span>
 
  
<span class="bold">property</span> <br/>
+
'''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.
The requested property value
+
<syntaxhighlight lang="lua">
{{i18n|GetProperty}}
+
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:
  • win
  • mac
  • ios
  • android
  • linux
  • ps4
  • xbox1
  • html5
"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