Difference between revisions of "UpdateData (CMS)"

From The Official Visionaire Studio: Adventure Game Engine Wiki
m
 
Line 7: Line 7:
  
 
This small function allows you to quickly update multiple types of data by passing a linked table through the function.
 
This small function allows you to quickly update multiple types of data by passing a linked table through the function.
<hr>
 
{| class="toccolours mw-collapsible mw-collapsed ts"
 
|-
 
! Available Data Types
 
|-
 
| Bool: a boolean value containing <span class="green">true</span> or <span class="red">false</span>
 
|-
 
| Int: an integer number, i.e: 7
 
|-
 
| Str: a string of text, i.e: "hello world"
 
|}
 
  
  
Line 26: Line 15:
 
local tbl = {
 
local tbl = {
  
{name = "condition_1", val = true, typ = "bool"},
+
{name = "condition_1", val = true},
{name = "condition_2", val = false, typ = "bool"},
+
{name = "condition_2", val = false},
{name = "value_1", val = 10, typ = "int"},
+
{name = "value_1", val = 10},
{name = "value_1", val = "hello world", typ = "str"}
+
{name = "value_1", val = "hello world"}
  
 
}
 
}
Line 41: Line 30:
 
function updateData(t)
 
function updateData(t)
 
  for i = 1, #t do -- iterate through table stored in the t input variable
 
  for i = 1, #t do -- iterate through table stored in the t input variable
   if t[i].typ == "bool" then -- check if condition
+
   if type(t[i].val) == "boolean" then -- check if condition
 
   Conditions[ t[i].name ].Value = t[i].val -- update condition
 
   Conditions[ t[i].name ].Value = t[i].val -- update condition
   elseif t[i].typ == "int" then -- check if value (number)
+
   elseif type(t[i].val) == "number" then -- check if value (number)
 
   Values[ t[i].name ].Int = t[i].val -- update value
 
   Values[ t[i].name ].Int = t[i].val -- update value
   elseif t[i].typ == "str" then -- check if value (string)
+
   elseif type(t[i].val) == "string" then -- check if value (string)
 
   Values[ t[i].name ].String = t[i].val -- update value
 
   Values[ t[i].name ].String = t[i].val -- update value
 
   end
 
   end
Line 58: Line 47:
 
! style="text-align:left" | Name !! style="text-align:left" | Type !! style="text-align:left;width:80%" | Description
 
! style="text-align:left" | Name !! style="text-align:left" | Type !! style="text-align:left;width:80%" | Description
 
|-
 
|-
| t || table || This should be a table or linked table containing the "names" of the visobj that you want to update, along with the "data type", & the data value.
+
| t || table || This should be a table or linked table containing the "names" of the visobj that you want to update, along with the data you want to update it with.
 
|}{{toc}}
 
|}{{toc}}

Latest revision as of 17:40, 21 August 2022

Name Type By
updateData({t}) Definition AFRLme

This small function allows you to quickly update multiple types of data by passing a linked table through the function.


Instructions

1. Add the main script to the Visionaire Studio Script Editor & set the script as a definition script.
2. Usage example: update all visobj listed in the linked table.

local tbl = {

{name = "condition_1", val = true},
{name = "condition_2", val = false},
{name = "value_1", val = 10},
{name = "value_1", val = "hello world"}

}

updateData(tbl)


Main Script

function updateData(t)
 for i = 1, #t do -- iterate through table stored in the t input variable
  if type(t[i].val) == "boolean" then -- check if condition
   Conditions[ t[i].name ].Value = t[i].val -- update condition
  elseif type(t[i].val) == "number" then -- check if value (number)
   Values[ t[i].name ].Int = t[i].val -- update value
  elseif type(t[i].val) == "string" then -- check if value (string)
   Values[ t[i].name ].String = t[i].val -- update value
  end
 end
end


Syntax Breakdown

Name Type Description
t table This should be a table or linked table containing the "names" of the visobj that you want to update, along with the data you want to update it with.