![MACROMEDIA DIRECTOR MX 2004-DIRECTOR SCRIPTING Reference Download Page 577](http://html1.mh-extra.com/html/macromedia/director-mx-2004-director-scripting/director-mx-2004-director-scripting_reference_3321720577.webp)
value()
577
These two Lingo statements are also equivalent:
x = (the mouseH - 10) / (the 10)
x = value("(the mouseH - 10) / (the 10)")
Expressions that Lingo cannot parse will produce unexpected results, but will not produce Lingo
errors. The result is the value of the initial portion of the expression up to the first syntax error
found in the string.
The
value()
function can be useful for parsing expressions input into text fields by end-users,
string expressions passed to Lingo by Xtra extensions, or any other expression you need to convert
from a string to a Lingo value.
Keep in mind that there may be some situations where using
value()
with user input can be
dangerous, such as when the user enters the name of a custom handler into the field. This will
cause the handler to be executed when it is passed to
value()
.
Do not confuse the actions of the value function with the
integer()
and
float()
functions.
Parameters
stringExpression
Required. Specifies the string from which a value is returned. The string can
be any expression that Lingo can understand.
Example
This statement displays the numerical value of the string
"the sqrt of" && "2.0"
:
put value("the sqrt of" && "2.0")
The result is 1.4142.
This statement displays the numerical value of the string “penny”:
put value("penny")
The resulting display in the Message window is
VOID
, because the word
penny
has no
numerical value.
You can convert a string that is formatted as a list into a true list by using this syntax:
myString = "[" & QUOTE & "cat" & QUOTE & ", " & QUOTE & "dog" & QUOTE & "]"
myList = value(myString)
put myList
-- ["cat", "dog"]
This allows a list to be placed in a field or text cast member and then extracted and easily
reformatted as a list.
This statement parses the string "3 5" and returns the value of the portion of the string that Lingo
understands:
put value("3 5")
-- 3
See also
string()
,
integer()
,
float()
Summary of Contents for DIRECTOR MX 2004-DIRECTOR SCRIPTING
Page 1: ...DIRECTOR MX 2004 Director Scripting Reference...
Page 48: ...48 Chapter 2 Director Scripting Essentials...
Page 100: ...100 Chapter 4 Debugging Scripts in Director...
Page 118: ...118 Chapter 5 Director Core Objects...
Page 594: ...594 Chapter 12 Methods...
Page 684: ...684 Chapter 14 Properties See also DVD...
Page 702: ...702 Chapter 14 Properties See also face vertices vertices flat...
Page 856: ...856 Chapter 14 Properties JavaScript syntax sprite 15 member member 3 4...
Page 1102: ...1102 Chapter 14 Properties...