Skip to content

Commit 44d5d03

Browse files
committed
docs: Document field values
1 parent 33c88ca commit 44d5d03

1 file changed

Lines changed: 36 additions & 0 deletions

File tree

docs/Block sections.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,42 @@ Value MySection::someBlock(const BlockArgs &args) {
9494
}
9595
```
9696
97+
### Adding field values
98+
If a field uses a predefined set of string values, for example rotation style `left-right`, `all around` and `don't rotate`,
99+
you can assign integer IDs to them to speed up the execution of scripts.
100+
```cpp
101+
class MySection : public IBlockSection {
102+
...
103+
enum FieldValues {
104+
RotateLeftRight,
105+
RotateAllAround,
106+
DoNotRotate
107+
};
108+
...
109+
};
110+
111+
MySection::MySection() {
112+
...
113+
addField("SOME_MENU", SOME_MENU);
114+
addFieldValue("left-right", RotateLeftRight);
115+
addFieldValue("all around", RotateAllAround);
116+
addFieldValue("don't rotate", DoNotRotate);
117+
}
118+
```
119+
Use the \link libscratchcpp::Field::specialValueId() specialValueId() \endlink function to get the ID of the value:
120+
```cpp
121+
Value MySection::someBlock(const BlockArgs &args) {
122+
switch(args.field(SOME_MENU)->specialValueId()) {
123+
case RotateLeftRight:
124+
...
125+
...
126+
}
127+
return Value();
128+
}
129+
```
130+
\note Don't confuse \link libscratchcpp::Field::specialValueId() specialValueId() \endlink with \link libscratchcpp::Field::valueId() valueId() \endlink
131+
because \link libscratchcpp::Field::valueId() valueId() \endlink stores the ID of the block, variable, list or broadcast selected in the dropdown list.
132+
97133
### Registering the block section
98134
Block sections are registered in the \link libscratchcpp::IExtension::registerSections() registerSections() \endlink
99135
function of an extension:

0 commit comments

Comments
 (0)