1. If you want help with your code, SHOW US YOUR CODE.
We can't read your mind, or see your screen. We don't know what your code looks like. We don't know what changes you have tried to make. We don't know what your error message says. If you want us to help you with your code, we need to actually see your code.
Don't post pseudo-code. Your addon is not a trade secret or national security. If you are not willing to show the actual code you are working with, we cannot answer any questions about why it doesn't work, what you are doing wrong, or what you need to change.
If your code is more than 20-30 lines, use a pastebin service: