Have you tried using the script templates that exist in the community? It can be a good example for you to learn.