12-26-2022 Belated update (from SDK 7.2) with default parameter values and image of fully-loaded myBlock

Westside Robotics
2022-12-26 10:34:38 -08:00
parent 871b7316ba
commit 7dd2f801fd

@ -129,7 +129,7 @@ This tutorial has three more sections with myBlocks guidelines, followed by **si
# Annotation Details
The required **annotation** ```@ExportToBlocks``` has optional fields, which may be listed in any order. These fields allow a myBlock to have a custom **comment**, **tooltip**, and **parameter labels**.
The required **annotation** ```@ExportToBlocks``` has optional fields, which may be listed in any order. These fields allow a myBlock to have a custom **comment**, **tooltip**, **parameter labels**, and **parameter default values**.
<p align="center">[[/images/Custom-FTC-Blocks-(myBlocks)/a0220-BlockWithBenefits.png|annotation details]]<p>
<!--
@ -154,19 +154,39 @@ The required **annotation** ```@ExportToBlocks``` has optional fields, which may
In the Hello World example, you may have noticed that the parameter label **Recipient** was not the same as the Java input parameter name **greetingRecipient**. They don't need to be the same. One is for the Blocks user, the other is for the Java programmer. Just list them in the correct/same order, so their meanings correspond.
In fact you don't need to label every input; a default label will instead show the declared type (e.g. String, boolean, int, double, etc.). In any case each grey socket will contain a sample of the required type (e.g. A, false, 0), with an appropriate tooltip.
If you don't label the inputs, a default label will instead show each declared type (e.g. String, boolean, int, double, etc.). In any case each grey socket will contain a **generic sample** of the required type (e.g. A, false, 0), with an appropriate tooltip. See below to customize this value.
If the number of parameter labels does not match the actual number of Java parameters, **all** custom label will be ignored. Instead the default labels will be displayed.
A myBlock may have up to 21 parameters... not recommended! Keep things simple.
### Parameter Default Values
New for SDK version 7.2, you may specify **default values** for all myBlock parameters (not just some of them).
Just add the annotation field `parameterDefaultValues`, formatted like the `parameterLabels` field with curly braces.
- Default values are separated by a comma. Line breaks may be used between values.
- For a single parameter, curly braces can be omitted: ```parameterDefaultValues = "999"```.
Be sure to list the default values in the **same order** as the parameters in the <i>method signature</i> and the list of parameter labels. Also make sure each default value is the correct **Java type**, matching its parameter.
If the number of default values does not match the actual number of Java parameters, **all** default values will be ignored. Instead the generic values will be displayed (or blank for type String).
### Other Annotation Notes
Two more optional annotation fields are:
- **heading**, such as "My Amazing myBlock"
- **color**, without quotes, just a color number. For example 155 is green, 255 is blue. Check it out!
Here's a sample myBlock using all these features:
<p align="center">[[/images/Custom-FTC-Blocks-(myBlocks)/a0270-parameter-defaults.png|complete myBlock class]]<p>
Notice that a default text value could be a suggested real parameter, or an **instruction** to the user (as shown here). Either can be edited by the user.
Again, the annotation ```@ExportToBlocks``` **must** appear immediately before each myBlock method, even if not using the optional fields.
Two more optional annotation labels, not illustrated here, are:
- **heading**, such as "My Amazing myBlock". The default heading is "call Java method".
- **color**, without quotes, just a color number (hue). For example 155 is green, 255 is blue. Default is 289. Check it out!
[<p align="right"><i>Return to Top</i>](#introduction)<p>
# More about Parameter Types