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...")
 
Line 21: Line 21:
 
== Main Script ==
 
== Main Script ==
 
<syntaxhighlight>
 
<syntaxhighlight>
function setCondition(v, n)
+
function setVal(v, n)
  if n:type = "number" then
+
  if type(n) == "number" then
   getObject("Values[" .. v .. "]"):setValue(VValueInt, n) else getObject("Values[" .. v .. "]"):setValue(VValueString, n)
+
   getObject("Values[" .. v .. "]"):setValue(VValueInt, n)
 +
elseif type(n) == "string" then
 +
  getObject("Values[" .. v .. "]"):setValue(VValueString, n)
 
  end
 
  end
 
end
 
end

Revision as of 20:53, 14 August 2014

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

Instructions

1. Add the main script to the Visionaire Studio Script Editor & set the script as a definition script.
2a. To use this function you should create an execute a script action containing...

setVal("value_name", 7) -- set integer value of "value_name" to 7

2b. Alternatively to set string value of a value...

setVal("value_name", "hello world") -- set string value of "value name" to "hello world"

Main Script

function setVal(v, n)
 if type(n) == "number" then
  getObject("Values[" .. v .. "]"):setValue(VValueInt, n)
 elseif type(n) == "string" then
  getObject("Values[" .. v .. "]"):setValue(VValueString, n)
 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.
n "string" or integer (number) This should contain a "string" or integer value.