I think using a saved value is a good approach
That example does not actually feature a saved value. It did, but I changed it to a regular variable, overlooking that "Using a saved value instead:" was still present.
is there a way to write up the code directly, like for example it looks like you pulled your code from a file somewhere, but nothing looks like that in the VAP file, which is - pretty opaque to me at the moment.
Anything that isn't an inline function is set up through the GUI, using the menu system. What I post is the contents of the action list, verbatim(right-click the action list and click "Copy All as Text" in the context menu).
You can add the modifications as follows:
Click "Other >", "Advanced ⯈", "Begin a Conditional(If Statement) Block ⯈", "Single Condition"
Click the "
Integer" tab(not "Small Integer")
In the "Variable Name" field, enter "trafficMenuItemPos"
In the dropdown, select "Has Not Been Set"
Click "OK"
Click "Other >", "Advanced ⯈", "Write a Value to the Event Log"
In the "Value" field, enter "Traffic menu item position unknown, use "traffic is now menu item" to set it"
In the "Color" dropdown, select "Red"
Click "OK"
Click "Other >", "Advanced ⯈", "Sounds ⯈", "Say Something with Text-To-Speech"
In the text field, enter "Traffic menu item position unknown, use "traffic is now menu item" to set it"
Click "OK"
What you have added up until now should be at the very top of the command, with no other actions preceding it.
Double-click the "End Condition" action in the action list to edit it
Check "When this block is reached, exit command if condition is met"
Click "OK"
Lower down on the action list, select all but one set of the consecutive
Press Down key and hold for 0,1 seconds and release
Pause 0,2 seconds
actions, and delete them(either press the "Del"/"Delete" key on your keyboard, or right-click your selection and click "Delete" in the context menu)
Select the remaining
Press Down key and hold for 0,1 seconds and release
Pause 0,2 seconds
actions
Click "Other >", "Advanced ⯈", "Add a Loop Start ⯈", "Repeat Certain Number of Times (For Loop)"
In the "Number of times" field, enter "trafficMenuItemPos"
Click "OK"
The added loop actions should automatically be placed around your selection.
Click "OK" to close the "Edit a Command" window
Click "New Command" on the top right of the "Edit a Profile" window
In the "When I say" field, enter "Traffic is now menu item [1..20]"
Click "Other >", "Advanced ⯈", "Set an Integer Value"
In the "Variable Name" field, enter "trafficMenuItemPos"
Click the "Convert Text/Token radio button
In the "Convert Text/Token" field, enter "{TXTNUM:"{CMD}"}"
Click "OK"
Click "OK" to close the "Add a Command" window
Click "Done" on the bottom right of the "Edit a Profile" window to save the changes