Difference between revisions of "SetConditions (CMS)"

From The Official Visionaire Studio: Adventure Game Engine Wiki
m
 
Line 48: Line 48:
 
| t || table || This should be a table or linked table containing the "names" of the conditions you want to update the boolean value of.
 
| t || table || This should be a table or linked table containing the "names" of the conditions you want to update the boolean value of.
 
|-
 
|-
| val || boolean or nil || This should contain a boolean value of <span style="color:green">true</span> or <span class="red">false</span>, or <span class="vsyellow">nil</span> if you want to toggle the conditions.
+
| val || boolean or nil || This should contain a boolean value of <span class="green">true</span> or <span class="red">false</span>, or <span class="vsyellow">nil</span> if you want to toggle the conditions.
 
|}{{toc}}
 
|}{{toc}}

Latest revision as of 20:53, 23 August 2022

Name Type By
setConditions({t}, val) Definition AFRLme

This small function allows you to quickly set or toggle the boolean value of multiple conditions.


Instructions

1. Add the main script to the Visionaire Studio Script Editor & set the script as a definition script.
2a. Usage example #1: update all listed conditions to true

setConditions({"example1", "example2", "example3"}, true)

2b. Usage example #2: toggle all listed conditions

setConditions({"cond1", "cond2", "cond3"})

2c. Usage example #3: update all listed conditions via linked table to true

local tbl = {"cond1", "cond2", "cond3"}

setConditions(tbl, true)


Main Script

function setConditions(t, val)
 for i = 1, #t do -- iterate through table stored in the t input variable
  if val == nil then -- check if condition should be toggle
   if Conditions[ t[i] ].Value then val = false else val = true end -- toggle val
  end
  -- + --
  Conditions[ t[i] ].Value = val -- update currently listed condition to val
 end
end


Syntax Breakdown

Name Type Description
t table This should be a table or linked table containing the "names" of the conditions you want to update the boolean value of.
val boolean or nil This should contain a boolean value of true or false, or nil if you want to toggle the conditions.