Difference between revisions of "VisionaireObject Command: getLinks"

From The Official Visionaire Studio: Adventure Game Engine Wiki
Line 1: Line 1:
<div class="toccolours mw-collapsible mw-collapsed tbl-ds">
+
Returns a table containing multiple VisionaireObjects.
<span class="bold">Function History</span>
 
<div class="mw-collapsible-content">
 
<div class="alt-bg">Available since v3.0</div>
 
</div></div>
 
  
  
Allows you to access, read & manipulate grouped data tables for objects, items, characters, conditions, & values etc...
+
== Syntax ==
 
+
<syntaxhighlight lang="lua">
 
+
getLinks(field)
<div class="toccolours mw-collapsible mw-collapsed tbl-ds">
 
<span class="bold">Additional Info</span>
 
<div class="mw-collapsible-content">
 
<div class="alt-bg">The data has to be iterated before you can access it.</div>
 
</div></div>
 
 
 
 
 
Syntax:
 
<syntaxhighlight>
 
getLinks(t_links)
 
 
</syntaxhighlight>
 
</syntaxhighlight>
  
  
Example 1: using getLinks as initial function.
+
== Parameters ==
<syntaxhighlight>
 
local lang = game:getLinks(VGameLanguages) -- store all available game languages
 
  
-- * iterate the data * --
+
{| class="ts"
for i = 1, table.maxn(lang) do -- for i = 1 to amount of entries in lang table do...
+
|-
print(lang[i]:getId().id .. ": " .. lang[i]:getName()) -- prints "language id: language name"
+
! style="width:15%" | Parameter
end
+
! style="width:15%" | Type
</syntaxhighlight>
+
! Description
 +
|-
 +
| field
 +
| integer
 +
| The field which specifies a list of VisionaireObject links. The field type must be "t_links".
 +
''Specify the field constant name (V + object table name in singular + field name) or the field id, see the example.''
 +
|}
  
Example 2: using getLinks after other functions
 
<syntaxhighlight>
 
local obj = game:getLink(VGameCurrentObject)
 
  
if not obj:isEmpty() then -- if obj is not empty do...
+
== Return values ==
if obj:getId().tableId == eCharacters then obj = obj:getLinks(VCharacterActions) else obj = obj:getLinks(VObjectActions) end -- check if obj is a character or an object
 
-- * iterate the data * --
 
for i = 1, table.maxn(obj) do -- for i = 1 to amount of entries in obj table do...
 
  print(i .. ": " .. obj[i]:getName()) -- prints "incremental value: action name"
 
end
 
end
 
</syntaxhighlight>
 
  
 +
{| class="ts"
 +
|-
 +
! style="width:15%" | Type
 +
! Description
 +
|-
 +
| table of t_links
 +
| The table of VisionaireObjects linked in the field
 +
|}
  
<span class="bold underline">Arguments</span>
 
  
'''t_links''': text <br/>
+
== Examples ==
The name of the grouped data structure object table.
 
  
 +
'''Example 1:''' Print the names of all game languages to the log.
 +
<syntaxhighlight lang="lua">
 +
-- Specify the field constant name or the field id
 +
local lang = game:getLinks(VGameLanguages)
 +
local lang = game:getLinks(259)
  
<span class="bold underline">Flags</span>
+
-- Iterate the table and print the language ids and names
 +
for i = 1, #lang do
 +
  print(lang[i]:getId().id .. ": " .. lang[i]:getName())
 +
end
  
none
+
-- The shorthand notation offers a more convenient way to achieve the same
 +
local lang = game.Languages
  
 
+
for i = 1, #lang do
<span class="bold underline">Return</span>
+
  print(lang[i].id .. ": " .. lang[i].name)
 
+
end
'''object''' <br/>
+
</syntaxhighlight>
Returns the data from the linked objects table; or returns empty.
+
{{toc}}

Revision as of 17:16, 25 August 2023

Returns a table containing multiple VisionaireObjects.


Syntax

getLinks(field)


Parameters

Parameter Type Description
field integer The field which specifies a list of VisionaireObject links. The field type must be "t_links".

Specify the field constant name (V + object table name in singular + field name) or the field id, see the example.


Return values

Type Description
table of t_links The table of VisionaireObjects linked in the field


Examples

Example 1: Print the names of all game languages to the log.

-- Specify the field constant name or the field id
local lang = game:getLinks(VGameLanguages)
local lang = game:getLinks(259)

-- Iterate the table and print the language ids and names
for i = 1, #lang do
  print(lang[i]:getId().id .. ": " .. lang[i]:getName())
end

-- The shorthand notation offers a more convenient way to achieve the same
local lang = game.Languages

for i = 1, #lang do
  print(lang[i].id .. ": " .. lang[i].name)
end