Return
(→Example 1) |
|||
(6 intermediate revisions by one user not shown) | |||
Line 1: | Line 1: | ||
− | This command is a [[Flow Commands|Flow Command]]. This command exits the current command or function and allows custom functions to return a value. | + | This command is a [[Flow Commands|Flow Command]]. This command exits the current command or function and allows custom functions to return a value. |
− | + | ||
− | + | This command is designed to allow the user to re-use code in the form of custom functions where a value is returned. | |
− | + | ||
+ | This command is used within the [[Define|define]] command. | ||
+ | |||
+ | |||
+ | '''Return Value:''' the value that is being returned from the custom functions. | ||
+ | |||
+ | |||
+ | == Example 1 == | ||
+ | <pre> | ||
+ | navigate("http://ubotstudio.com/playground/simple-form", "Wait") | ||
define $my test function { | define $my test function { | ||
set(#test, $eval($add(5, 2)), "Global") | set(#test, $eval($add(5, 2)), "Global") | ||
Line 10: | Line 17: | ||
} | } | ||
type text(<about me textarea>, $my test function(), "Standard") | type text(<about me textarea>, $my test function(), "Standard") | ||
+ | |||
</pre> | </pre> | ||
+ | |||
Running the above script creates a function that calculates 5+2 in the variable "test". The return command sets the entire function to the value of the calculation in the variable. | Running the above script creates a function that calculates 5+2 in the variable "test". The return command sets the entire function to the value of the calculation in the variable. | ||
The function is then used to place the result in the specified field. | The function is then used to place the result in the specified field. | ||
− | [[File:return. | + | |
+ | [[File:return.jpg]] | ||
+ | |||
+ | == Additional Information == | ||
+ | |||
+ | Did you know that you can break a loop within a [[define]] command with a return command? | ||
+ | |||
+ | You can place the loop in a define, and the return command will break the loop, exit out of the define command and run the script that comes after the define command. | ||
+ | |||
+ | <pre> | ||
+ | define blue { | ||
+ | loop(1) { | ||
+ | alert("Hi!") | ||
+ | return(0) | ||
+ | alert("Howdy Partner!") | ||
+ | } | ||
+ | } | ||
+ | blue() | ||
+ | alert("Hello There!") | ||
+ | |||
+ | </pre> | ||
+ | |||
+ | |||
+ | The following example will run the alert that displays the greeting "Hi!" | ||
+ | |||
+ | Because of the return command, the script will exit the define command and run the command after that, which is an alert that displays the greeting "Hello There!". | ||
+ | |||
+ | [[File:return0.jpg]] |
Latest revision as of 17:01, 7 September 2014
This command is a Flow Command. This command exits the current command or function and allows custom functions to return a value.
This command is designed to allow the user to re-use code in the form of custom functions where a value is returned.
This command is used within the define command.
Return Value: the value that is being returned from the custom functions.
[edit] Example 1
navigate("http://ubotstudio.com/playground/simple-form", "Wait") define $my test function { set(#test, $eval($add(5, 2)), "Global") return(#test) } type text(<about me textarea>, $my test function(), "Standard")
Running the above script creates a function that calculates 5+2 in the variable "test". The return command sets the entire function to the value of the calculation in the variable.
The function is then used to place the result in the specified field.
[edit] Additional Information
Did you know that you can break a loop within a define command with a return command?
You can place the loop in a define, and the return command will break the loop, exit out of the define command and run the script that comes after the define command.
define blue { loop(1) { alert("Hi!") return(0) alert("Howdy Partner!") } } blue() alert("Hello There!")
The following example will run the alert that displays the greeting "Hi!"
Because of the return command, the script will exit the define command and run the command after that, which is an alert that displays the greeting "Hello There!".