Difference between revisions of "SetVal (CMS)"

From The Official Visionaire Studio: Adventure Game Engine Wiki
m (Text replacement - "wikitable" to "ts")
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", n) || Definition || AFRLme
+
| setVal("v", d) || 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 integer number belonging to a value with optional duration for integers, in case you need it.
 +
<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 setVal(v, n)
+
function setVal(v, d, duration)
  if type(n) == "number" then
+
duration = duration or 0 -- fallback in case duration equals nil
   getObject("Values[" .. v .. "]"):setValue(VValueInt, n)
+
-- + --
  elseif type(n) == "string" then
+
  if type(d) == "number" then -- check if number
   getObject("Values[" .. v .. "]"):setValue(VValueString, n)
+
   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 ==
Line 37: 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}}

Revision as of 18:02, 23 August 2022

Name Type By
setVal("v", d) 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.


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.