Difference between revisions of "SetConditions (CMS)"
From The Official Visionaire Studio: Adventure Game Engine Wiki
(Created page with "{| class="ts" style="width:100%" |- ! style="text-align:left" | Name !! style="text-align:left" | Type !! style="text-align:left" | By |- | setConditions({t}, val) || Definiti...") |
|||
Line 31: | Line 31: | ||
function setConditions(t, val) | function setConditions(t, val) | ||
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 val == nil then | + | if val == nil then -- check if condition should be toggle |
− | if Conditions[ t[i] ].Value then | + | if Conditions[ t[i] ].Value then val = false else val = true end -- toggle val |
− | |||
− | |||
end | end | ||
+ | -- + -- | ||
+ | Conditions[ t[i] ].Value = val -- update currently listed condition to val | ||
end | end | ||
end | end |
Revision as of 14:39, 21 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. |