Difference between revisions of "SetVal (CMS)"

From The Official Visionaire Studio: Adventure Game Engine Wiki
m
 
(One intermediate revision by the same user not shown)
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
 
|-
 
|-
| setVal("v", d) || Definition || AFRLme
+
| setVal("v", d, duration) || Definition || AFRLme
 
|}
 
|}
  
This small function allows you to quickly set the string or integer number belonging to a value with optional duration for integers, in case you need it.
+
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>
 
<hr>
 
{| class="ts"
 
{| class="ts"

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.