Skip to content, Skip to search

Changes

Script Parameters

158 bytes added, 15:41, 18 March 2016
Basic syntax: Clarify some parameter behavior
</source>
We see that an input parameter <code>name</code> of type <code>String</code> is declared. This <code>@arameters</code> are handled automatically by the framework; if we run this script when the User Interface is available (e.g. from the script editor), the <code>name</code> parameter will automatically be harvested via a pop-up dialog when the script is run.:
When the script is completed, we expect to have a <code>String</code> variable named <code>greeting</code> which will be displayed as appropriate, based on the variable type.
Note that if we added an extra comment to the top of our script we would break the script, as the parameters would not be harvested or displayed due to violation of the second parameter rule[[File: ScriptParams.png|450px]]
<source lang="python">
# A simple python script
# @String name
# @OUTPUT String greeting
We could also run this script [[Headless# A Jython script with Running_scripts_in_headless_mode|headlessly]], thanks to the general nature of <code>@parameters</code>.# It is the duty of the scripting framework to harvest# When the 'name' parameter from the userscript is completed, and then display# any <code>@OUTPUT</code> variables are handled by the 'greeting' output parameterframework, based on its their type. In this case we expect the <code>greeting</code> variable to be printed, since it is a <code>string</code>.
greeting = "Hello, " + name + "!"
</source>
Keep {{Warning | Note that if we added an extra comment to the top of our script we would break the script, as the parameters would not be harvested or displayed due to violation of the second parameter rule: <source lang="python"># Because of this in mind when adding documentation to your scripts.comment, the following parameters will NOT be recognized# @String name# @OUTPUT String greeting</source>}}
== Parameter properties ==
Bureaucrat, emailconfirmed, incoming, administrator, uploaders
735
edits