Difference between revisions of "Workflow Functions"

From The Official Visionaire Studio: Adventure Game Engine Wiki
 
(52 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
What is a workflow function? A workflow function is a function that you can script to save yourself time by reducing the amount of work you need to do. The function could perform one specific task, or it could perform multiple tasks.
 
What is a workflow function? A workflow function is a function that you can script to save yourself time by reducing the amount of work you need to do. The function could perform one specific task, or it could perform multiple tasks.
 +
<hr>
 +
{| class="ts"
 +
|-
 +
| ''Quick note: Workflow functions are not meant to replace action parts. Mostly they are used to save time while scripting, by reducing the amount of code you need to type out, which could be done by shortening what you have to type out, or by iteration.''
 +
|}
 +
<hr>
 +
I have provided a few examples of workflow functions below, but for a full list of workflow functions check out the [[Compiled_Index_of_Lua_Scripts_for_Visionaire_Studio#Workflow_Functions|workflow functions]] section of the [[Compiled_Index_of_Lua_Scripts_for_Visionaire_Studio|script index]] wiki page.
 +
<hr>
 +
{| class="ts"
 +
|-
 +
! style="text-align:left" | Name !! style="text-align:left" | Description
 +
|-
 +
| setCondition(cond, val, path) || Update or toggle the specified condition via global or direct linking.
 +
|}
  
Anyway, let's crack on...
+
Syntax:
 
+
setCondition("condition name", boolean value or nil, path to condition)
 
+
Scripts > definition:
== Example #1: Condition ==
 
 
 
Script section > definition type script:
 
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">
function setCond(cond, val, cs)
+
function setCondition(cond, val, path)
  if cs ~= nil then cond = game.CurrentScene.Conditions[cond] else cond = Conditions[cond] end -- check global or direct 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 val == nil then -- check if condition should be toggled
   if cond.Value then cond.Value = false else Cond.Value = true end -- toggle condition
+
   if cond.Value then cond.Value = false else cond.Value = true end -- toggle condition
 
  else
 
  else
 
   cond.Value = val -- update condition based on val (true or false)
 
   cond.Value = val -- update condition based on val (true or false)
Line 20: Line 31:
 
Usage example #1: set condition example as true, access globally
 
Usage example #1: set condition example as true, access globally
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">
setCond("example", true)
+
setCondition("example", true)
 
</syntaxhighlight>
 
</syntaxhighlight>
 
Usage example #2: toggle condition example, access condition belonging to current scene
 
Usage example #2: toggle condition example, access condition belonging to current scene
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">
setCond("example", nil, true)
+
setCondition("example", nil, game.CurrentScene)
 +
</syntaxhighlight>
 +
<hr>
 +
 
 +
<hr>
 +
{| class="ts"
 +
|-
 +
! style="text-align:left" | Name !! style="text-align:left" | Description
 +
|-
 +
| setConditions(t, val) || Iterate through a table of conditions & update the boolean value belonging to them.
 +
|}
 +
 
 +
Syntax:
 +
setConditions({table}, boolean value)
 +
Scripts > definition:
 +
<syntaxhighlight lang="lua">
 +
function setConditions(t, val)
 +
for i = 1, #t do -- iterate through table stored in the t input variable
 +
  Conditions[ t[i] ].Value = val -- update all conditions listed in t variable to val
 +
end
 +
end
 +
</syntaxhighlight>
 +
Usage: update all listed conditions to true
 +
<syntaxhighlight lang="lua">
 +
setConditions({"example1", "example2", "example3"}, true)
 +
</syntaxhighlight>
 +
<hr>
 +
 
 +
<hr>
 +
{| class="ts"
 +
|-
 +
! style="text-align:left" | Name !! style="text-align:left" | Description
 +
|-
 +
| updateData(t) || Iterate through a table containing multiple types of data & update the value belonging to them.
 +
|}
 +
 
 +
Syntax:
 +
updateData(table)
 +
 
 +
Scripts > definition:
 +
<syntaxhighlight lang="lua">
 +
function updateData(t)
 +
for i = 1, #t do -- iterate through table stored in the t input variable
 +
  if type(t[i].val) == "boolean" then -- check if condition
 +
  Conditions[ t[i].name ].Value = t[i].val -- update condition
 +
  elseif type(t[i].val) == "number" then -- check if value (number)
 +
  Values[ t[i].name ].Int = t[i].val -- update value
 +
  elseif type(t[i].val) == "string" then -- check if value (string)
 +
  Values[ t[i].name ].String = t[i].val -- update value
 +
  end
 +
end
 +
end
 +
</syntaxhighlight>
 +
Usage: update mixed data types using a table & the function
 +
<syntaxhighlight lang="lua">
 +
local tbl = {
 +
 
 +
{name = "condition_1", val = true},
 +
{name = "condition_2", val = false},
 +
{name = "value_1", val = 10},
 +
{name = "value_1", val = "hello world"}
 +
 
 +
}
 +
 
 +
updateData(tbl) -- pass the tbl data through the function
 
</syntaxhighlight>
 
</syntaxhighlight>

Latest revision as of 16:46, 21 August 2022

What is a workflow function? A workflow function is a function that you can script to save yourself time by reducing the amount of work you need to do. The function could perform one specific task, or it could perform multiple tasks.


Quick note: Workflow functions are not meant to replace action parts. Mostly they are used to save time while scripting, by reducing the amount of code you need to type out, which could be done by shortening what you have to type out, or by iteration.

I have provided a few examples of workflow functions below, but for a full list of workflow functions check out the workflow functions section of the script index wiki page.


Name Description
setCondition(cond, val, path) Update or toggle the specified condition via global or direct linking.

Syntax:

setCondition("condition name", boolean value or nil, path to condition)

Scripts > definition:

function setCondition(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

Usage example #1: set condition example as true, access globally

setCondition("example", true)

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

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


Name Description
setConditions(t, val) Iterate through a table of conditions & update the boolean value belonging to them.

Syntax:

setConditions({table}, boolean value)

Scripts > definition:

function setConditions(t, val)
 for i = 1, #t do -- iterate through table stored in the t input variable
  Conditions[ t[i] ].Value = val -- update all conditions listed in t variable to val
 end
end

Usage: update all listed conditions to true

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


Name Description
updateData(t) Iterate through a table containing multiple types of data & update the value belonging to them.

Syntax:

updateData(table)

Scripts > definition:

function updateData(t)
 for i = 1, #t do -- iterate through table stored in the t input variable
  if type(t[i].val) == "boolean" then -- check if condition
   Conditions[ t[i].name ].Value = t[i].val -- update condition
  elseif type(t[i].val) == "number" then -- check if value (number)
   Values[ t[i].name ].Int = t[i].val -- update value
  elseif type(t[i].val) == "string" then -- check if value (string)
   Values[ t[i].name ].String = t[i].val -- update value
  end
 end
end

Usage: update mixed data types using a table & the function

local tbl = {

{name = "condition_1", val = true},
{name = "condition_2", val = false},
{name = "value_1", val = 10},
{name = "value_1", val = "hello world"}

}

updateData(tbl) -- pass the tbl data through the function