Difference between revisions of "Workflow Functions"
From The Official Visionaire Studio: Adventure Game Engine Wiki
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> | ||
− | + | == Examples == | |
− | + | {| class="ts" | |
− | = | + | |- |
− | + | ! style="text-align:left" | Name | Description | Author | |
− | + | |- | |
+ | | setCond() || Update or toggle specified condition via global or direct linking || AFRLme | ||
+ | |- | ||
+ | | Syntax: | ||
+ | <syntaxhighlight lang="lua"> | ||
+ | setCond(condition name, boolean value or nil, condition belongs to current scene?) | ||
+ | </syntaxhighlight> | ||
+ | |- | ||
+ | | Scripts (definition): | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
function setCond(cond, val, cs) | function setCond(cond, val, cs) | ||
Line 18: | Line 32: | ||
end | end | ||
</syntaxhighlight> | </syntaxhighlight> | ||
− | 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) | setCond("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) | setCond("example", nil, true) | ||
</syntaxhighlight> | </syntaxhighlight> | ||
+ | |} | ||
Line 73: | Line 90: | ||
updateData(tbl) -- pass the tbl data through the function | updateData(tbl) -- pass the tbl data through the function | ||
</syntaxhighlight> | </syntaxhighlight> | ||
+ | |||
+ | {{toc}} |
Revision as of 19:46, 20 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. |
Examples
Name | Description | Author | ||
---|---|---|
setCond() | Update or toggle specified condition via global or direct linking | AFRLme |
Syntax:
setCond(condition name, boolean value or nil, condition belongs to current scene?)
| ||
Scripts (definition):
function setCond(cond, val, cs)
if cs ~= nil then cond = game.CurrentScene.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
setCond("example", true)
| ||
Usage example #2: toggle condition example, access condition belonging to current scene
setCond("example", nil, true)
|
Example #2: Basic Iteration
Script section > definition type script:
function updateConditions(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
updateConditions({"example1", "example2", "example3"}, true)
Example #3: Advanced Iteration
Script section > definition type script:
function updateData(t)
for i = 1, #t do -- iterate through table stored in the t input variable
if t[i].typ == "bool" then -- check if condition
Conditions[ t[i].name ].Value = t[i].val -- update condition
elseif t[i].typ == "int" then -- check if value (number)
Values[ t[i].name ].Int = t[i].val -- update value
elseif t[i].typ == "str" 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, typ = "bool"},
{name = "condition_2", val = false, typ = "bool"},
{name = "value_1", val = 10, typ = "int"},
{name = "value_1", val = "hello world", typ = "str"}
}
updateData(tbl) -- pass the tbl data through the function