Difference between revisions of "SetCondition (CMS)"
From The Official Visionaire Studio: Adventure Game Engine Wiki
m |
|||
(One intermediate revision by the same user not shown) | |||
Line 24: | Line 24: | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
function setCondition(cond, val, path) | function setCondition(cond, val, path) | ||
− | if path ~= nil then cond = path.Conditions[cond] else cond = Conditions[cond] end -- check global or direct | + | if path ~= nil then cond = path.Conditions[cond] else cond = Conditions[cond] end -- check global access or direct link |
-- + -- | -- + -- | ||
if val == nil then -- check if condition should be toggled | if val == nil then -- check if condition should be toggled | ||
Line 42: | Line 42: | ||
| cond || "string" || This should be a "string" value containing the name of the condition you want to update the boolean value of. | | cond || "string" || This should be a "string" value containing the name of the condition you want to update the boolean value of. | ||
|- | |- | ||
− | | val || boolean or nil || This should contain a boolean value of <span | + | | 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 condition. |
|- | |- | ||
| path || path || This should contain the direct path to the condition, for example: <span class="inlinecode">game.CurrentScene</span> or <span class="inlinecode">Scenes["example"]</span> or <span class="inlinecode">Characters["Tom"]</span>, etc. | | path || path || This should contain the direct path to the condition, for example: <span class="inlinecode">game.CurrentScene</span> or <span class="inlinecode">Scenes["example"]</span> or <span class="inlinecode">Characters["Tom"]</span>, etc. | ||
|}{{toc}} | |}{{toc}} |
Latest revision as of 19:53, 23 August 2022
Name | Type | By |
---|---|---|
setCondition("cond", val, path) | Definition | AFRLme |
This small function allows you to quickly set or toggle the boolean value of a condition.
Instructions
1. Add the main script to the Visionaire Studio Script Editor & set the script as a definition script.
2a. Usage example #1: set condition example as true, access globally
setCondition("example", true)
2b. Usage example #2: toggle condition example, access condition belonging to current scene
setCondition("example", nil, game.CurrentScene)
Main Script
function setCondition(cond, val, path)
if path ~= nil then cond = path.Conditions[cond] else cond = Conditions[cond] end -- check global access or direct link
-- + --
if val == nil then -- check if condition should be toggled
if cond.Value then cond.Value = false else cond.Value = true end -- toggle condition
else
cond.Value = val -- update condition based on val (true or false)
end
end
Syntax Breakdown
Name | Type | Description |
---|---|---|
cond | "string" | This should be a "string" value containing the name of the condition 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 condition. |
path | path | This should contain the direct path to the condition, for example: game.CurrentScene or Scenes["example"] or Characters["Tom"], etc. |