State machine programming tips

From Tekkotsu Wiki

Jump to: navigation, search

Contents

Speaking Computed Text

SpeechNode provides a member variable textstream that you can write to in order to generate a string to speak. Do this by subclassing SpeechNode and writing to textstream from your doStart method:

 $nodeclass CountShapes : SpeechNode : doStart {
   textstream << "I saw " << camShS.allShapes.size() << " shapes in the camera image.";
 }

Console Input

Use =TM=>

Control Flow

Use =N=> if your node doesn't complete Use postStateCompletion to make your node complete Call stop() or transition to a dummy node or you won't be able to re-enter a node

Debugging: Speaking Node and Transition Names

Placing a backquote after a node class name causes the name of the node to be spoken upon entry. Placing a backquote after a transition class name causes the name of that transition to be spoken when the transition fires. Example:

foo: StateNode` =time1:T`(2000)=> bar: StateNode`

The above code will result in the speech "foo... time1 bar".