Difference between revisions of "SetCondition (CMS)"

From The Official Visionaire Studio: Adventure Game Engine Wiki
m (Text replacement - ""wikitable"" to ""ts"")
Line 3: Line 3:
 
! style="text-align:left" | Name !! style="text-align:left" | Type !! style="text-align:left" | By
 
! style="text-align:left" | Name !! style="text-align:left" | Type !! style="text-align:left" | By
 
|-
 
|-
| setCondition("c", v) || Definition || AFRLme
+
| setCondition("cond", val, path) || Definition || AFRLme
 
|}
 
|}
  
Line 10: Line 10:
 
== Instructions ==
 
== Instructions ==
 
1. Add the [[#Main_Script|main script]] to the Visionaire Studio Script Editor & set the script as a definition script.<br/>
 
1. Add the [[#Main_Script|main script]] to the Visionaire Studio Script Editor & set the script as a definition script.<br/>
2. To use this function you should create an ''execute a script'' action containing...
+
2a. Usage example #1: set condition example as true, access globally
<syntaxhighlight>
+
<syntaxhighlight lang="lua">
setCondition("condition_name", true)
+
setCond("example", true)
 
</syntaxhighlight>
 
</syntaxhighlight>
 +
2b. Usage example #2: toggle condition example, access condition belonging to current scene
 +
<syntaxhighlight lang="lua">
 +
setCond("example", nil, game.CurrentScene)
 +
</syntaxhighlight>
 +
  
 
== Main Script ==
 
== Main Script ==
<syntaxhighlight>
+
<syntaxhighlight lang="lua">
function setCondition(c, v)
+
function setCond(cond, val, path)
  getObject("Conditions[" .. c .. "]"):setValue(VConditionValue, v)
+
  if path ~= nil then cond = path.Conditions[cond] else cond = Conditions[cond] end -- check global or direct path
 +
-- + --
 +
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
 
end
 
</syntaxhighlight>
 
</syntaxhighlight>
 +
  
 
== Syntax Breakdown ==
 
== Syntax Breakdown ==
Line 27: Line 39:
 
! 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
 
|-
 
|-
| c || "string" || This should be a "string" value containing the name of the condition you want to check 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 || This should contain a boolean value of <span style="color:green">true</span> or <span class="red">false</span> or nil if you want to toggle the condition.
 
|-
 
|-
| v || boolean || This should contain a boolean value of <span style="color:green">true</span> or <span class="red">false</span>.
+
| path || path || This should contain the direct path to the condition, for example: <span class="inlinecode">game.CurrentScene</span>.
 
|}
 
|}

Revision as of 21:47, 20 August 2022

Name Type By
setCondition("cond", val, path) Definition AFRLme

This small function allows you to quickly set 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

setCond("example", true)

2b. Usage example #2: toggle condition example, access condition belonging to current scene

setCond("example", nil, game.CurrentScene)


Main Script

function setCond(cond, val, path)
 if path ~= nil then cond = path.Conditions[cond] else cond = Conditions[cond] end -- check global or direct path
 -- + --
 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 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.