Difference between revisions of "CheckCond (CMS)"

From The Official Visionaire Studio: Adventure Game Engine Wiki
(Created page with "{| class="wikitable" style="width:100%" |- ! style="text-align:left" | Name !! style="text-align:left" | Type !! style="text-align:left" | By |- | checkCond("cond") || Definit...")
 
m
 
(7 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{| class="wikitable" style="width:100%"
+
{| class="ts" style="width:100%"
 
|-
 
|-
 
! 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
 
|-
 
|-
| checkCond("cond") || Definition || AFRLme
+
| checkCond("c", path) || Definition || AFRLme
 
|}
 
|}
  
This small function allows you to quickly return the boolean value of a condition; ''should only be used with if queries''.
+
This small function allows you to quickly return the boolean value of a condition.
 +
 
  
 
== 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/>
2a. To check if condition returns <span style="color:green">true</span>, do something like this...
+
2a. Usage Example #1: check if globally accessed condition returns <span class="green">true</span>.
<syntaxhighlight>
+
<syntaxhighlight lang="lua">
 
if checkCond("condition_name") then
 
if checkCond("condition_name") then
 
  -- add some actions here...
 
  -- add some actions here...
 
end
 
end
 
</syntaxhighlight>
 
</syntaxhighlight>
2b. To check if condition returns <span class="red">false</span>, do something like this...
+
2b. Usage Example #2: check if globally accessed condition returns <span class="red">false</span>.
<syntaxhighlight>
+
<syntaxhighlight lang="lua">
 
if not checkCond("condition_name") then
 
if not checkCond("condition_name") then
 
  -- add some actions here...
 
  -- add some actions here...
 
end
 
end
 +
</syntaxhighlight>
 +
2c. Usage Example #3: check if condition linked to current scene returns <span class="green">true</span>.
 +
<syntaxhighlight lang="lua>
 +
if checkCond("condition_name", game.CurrentScene) then
 +
-- add some actions here...
 +
end
 +
</syntaxhighlight>
 +
2d. Usage Example #4: check if globally accessed condition returns <span class="green">true</span> via '''if lua result''' action part.
 +
<syntaxhighlight lang="lua">
 +
return checkCond("condition_name")
 
</syntaxhighlight>
 
</syntaxhighlight>
 +
  
 
== Main Script ==
 
== Main Script ==
<syntaxhighlight>
+
<syntaxhighlight lang="lua">
function checkCond(cond)
+
function checkCond(c, path)
  return getObject("Conditions[" .. cond .. "]"):getBool(VConditionValue)
+
  if path == nil then c = Conditions[c] else c = path.Conditions[c] end -- check global access or direct link
 +
return c -- return the boolean value belonging to the condition
 
end
 
end
 
</syntaxhighlight>
 
</syntaxhighlight>
 +
  
 
== Syntax Breakdown ==
 
== Syntax Breakdown ==
{| class="wikitable" style="width:100%"
+
{| class="ts" style="width:100%"
 
|-
 
|-
 
! 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
 
|-
 
|-
| cond || "string" || This should be a "string" value containing the name of the condition you want to check the boolean value of.
+
| c || "string" || This should be a "string" value containing the name of the condition you want to check the boolean value of.
|}
+
|-
 +
| 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}}

Latest revision as of 15:02, 23 August 2022

Name Type By
checkCond("c", path) Definition AFRLme

This small function allows you to quickly return 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: check if globally accessed condition returns true.

if checkCond("condition_name") then
 -- add some actions here...
end

2b. Usage Example #2: check if globally accessed condition returns false.

if not checkCond("condition_name") then
 -- add some actions here...
end

2c. Usage Example #3: check if condition linked to current scene returns true.

if checkCond("condition_name", game.CurrentScene) then
 -- add some actions here...
end

2d. Usage Example #4: check if globally accessed condition returns true via if lua result action part.

return checkCond("condition_name")


Main Script

function checkCond(c, path)
 if path == nil then c = Conditions[c] else c = path.Conditions[c] end -- check global access or direct link
 return c -- return the boolean value belonging to the condition
end


Syntax Breakdown

Name Type Description
c "string" This should be a "string" value containing the name of the condition you want to check the boolean value of.
path path This should contain the direct path to the condition, for example: game.CurrentScene or Scenes["example"] or Characters["Tom"], etc.