Difference between revisions of "Input"

From MiniScript Wiki
Jump to navigation Jump to search
(Created page with "<c>input</c> is a quasi-standard function in the MiniScript language that gets a string of input from the user. By "quasi-standard" we mean that it is not part of the MiniScr...")
 
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
 
<c>input</c> is a quasi-standard function in the MiniScript language that gets a string of input from the user.  By "quasi-standard" we mean that it is not part of the MiniScript core, but several implementations support it, and embedders are encouraged to add support for it whenever possible.
 
<c>input</c> is a quasi-standard function in the MiniScript language that gets a string of input from the user.  By "quasi-standard" we mean that it is not part of the MiniScript core, but several implementations support it, and embedders are encouraged to add support for it whenever possible.
  
Syntax:
+
=== Arguments ===
  
  input(''prompt'')
+
{| class="wikitable"
 +
|-
 +
! Parameter Name !! Default Value !! Meaning
 +
|-
 +
| prompt || "" || string to display to the user
 +
|}
  
The ''prompt'' is optional, and if supplied, is printed to output (as if with <c>[[print]]</c>).  The script then blocks while the user types a response, terminated by Return or Enter.  The text entered (without the terminating line break) is returned as the value of the function.
+
The ''prompt'' parameter is optional, and if supplied, is printed to output (as if with <c>[[print]]</c>).  The script then blocks while the user types a response, terminated by Return or Enter.  The text entered (without the terminating line break) is returned as the value of the function.
  
 
Note that <c>input</c> always returns a [[string]].  To interpret the input as a number, use <c>[[val]]</c>.
 
Note that <c>input</c> always returns a [[string]].  To interpret the input as a number, use <c>[[val]]</c>.
Line 18: Line 23:
 
[[Category:Mini Micro]]
 
[[Category:Mini Micro]]
 
[[Category:Command-Line]]
 
[[Category:Command-Line]]
 +
[[Category:Farmtronics]]

Latest revision as of 19:46, 26 January 2022

input is a quasi-standard function in the MiniScript language that gets a string of input from the user. By "quasi-standard" we mean that it is not part of the MiniScript core, but several implementations support it, and embedders are encouraged to add support for it whenever possible.

Arguments

Parameter Name Default Value Meaning
prompt "" string to display to the user

The prompt parameter is optional, and if supplied, is printed to output (as if with print). The script then blocks while the user types a response, terminated by Return or Enter. The text entered (without the terminating line break) is returned as the value of the function.

Note that input always returns a string. To interpret the input as a number, use val.

Example

The following example asks the user's age, and then reports their age in dog years.

age = input("How old are you? ").val
print "That's " + age*7 + " in dog years."