Difference between revisions of "SetVal (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 |- | setVal("v", n) || Definition...")
 
m
 
(4 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
 
|-
 
|-
| setVal("v", n) || Definition || AFRLme
+
| setVal("v", d, duration) || Definition || AFRLme
 
|}
 
|}
  
This small function allows you to quickly set the string or integer value of a value; ''automatically determines if '''n''' is a string or integer''.
+
This small function allows you to quickly set the string or immediately update the integer number belonging to to the specified value; or over x duration, just in case you need that functionality for some reason or other.
 +
<hr>
 +
{| class="ts"
 +
|-
 +
| ''Quick note: automatically determines if '''d''' is a string or integer.''
 +
|}
 +
<hr>
 +
 
  
 
== 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 use this function you should create an ''execute a script'' action containing...
+
2a. Usage Example #1: immediately update integer value of specified value to 7.
<syntaxhighlight>
+
<syntaxhighlight lang="lua">
setVal("value_name", 7) -- set integer value of "value_name" to 7
+
setVal("value_name", 7)
 +
</syntaxhighlight>
 +
2b. Usage Example #2: update integer value of specified value from current value to 7 over 250ms.
 +
<syntaxhighlight lang="lua">
 +
setVal("value_name", 7, 250)
 
</syntaxhighlight>
 
</syntaxhighlight>
2b. Alternatively to set string value of a value...
+
2c. Usage Example #3: update string belonging to the specified value to "hello world!".
<syntaxhighlight>
+
<syntaxhighlight lang="lua">
setVal("value_name", "hello world") -- set string value of "value name" to "hello world"
+
setVal("value_name", "hello world!")
 
</syntaxhighlight>
 
</syntaxhighlight>
 +
  
 
== Main Script ==
 
== Main Script ==
<syntaxhighlight>
+
<syntaxhighlight lang="lua">
function setCondition(v, n)
+
function setVal(v, d, duration)
  if n:type = "number" then
+
duration = duration or 0 -- fallback in case duration equals nil
   getObject("Values[" .. v .. "]"):setValue(VValueInt, n) else getObject("Values[" .. v .. "]"):setValue(VValueString, n)
+
-- + --
 +
  if type(d) == "number" then -- check if number
 +
   Values[v]:to(duration, {Int = d}) -- update integer belonging to the specified value
 +
elseif type(d) == "string" then -- check if string
 +
  Values[v].String = d -- update string belonging to the specified value
 
  end
 
  end
 
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
Line 35: Line 52:
 
| v || "string" || This should be a "string" value containing the name of the value you want to affect.
 
| v || "string" || This should be a "string" value containing the name of the value you want to affect.
 
|-
 
|-
| n || "string" or integer (number) || This should contain a "string" or integer value.
+
| d || "string" or integer || This should contain a "string" or number value.
|}
+
|-
 +
| duration || integer || This should contain a number value in milliseconds of how long you want the current integer value to take to get from the current value to the target value.
 +
|}{{toc}}

Latest revision as of 19:44, 23 August 2022

Name Type By
setVal("v", d, duration) Definition AFRLme

This small function allows you to quickly set the string or immediately update the integer number belonging to to the specified value; or over x duration, just in case you need that functionality for some reason or other.


Quick note: automatically determines if d is a string or integer.


Instructions

1. Add the main script to the Visionaire Studio Script Editor & set the script as a definition script.
2a. Usage Example #1: immediately update integer value of specified value to 7.

setVal("value_name", 7)

2b. Usage Example #2: update integer value of specified value from current value to 7 over 250ms.

setVal("value_name", 7, 250)

2c. Usage Example #3: update string belonging to the specified value to "hello world!".

setVal("value_name", "hello world!")


Main Script

function setVal(v, d, duration)
 duration = duration or 0 -- fallback in case duration equals nil
 -- + --
 if type(d) == "number" then -- check if number
  Values[v]:to(duration, {Int = d}) -- update integer belonging to the specified value
 elseif type(d) == "string" then -- check if string
  Values[v].String = d -- update string belonging to the specified value
 end
end


Syntax Breakdown

Name Type Description
v "string" This should be a "string" value containing the name of the value you want to affect.
d "string" or integer This should contain a "string" or number value.
duration integer This should contain a number value in milliseconds of how long you want the current integer value to take to get from the current value to the target value.