In my signature there is the link to an ingame tutorial that explains exactly such functions, but it is with A5. Nonetheless, the principles didn't change.