I have been doing my first delving into vendor scripting that handles how an object gets paid and subsequently gives inventory to the purchaser. There is a lot of stress on setting up your script actually check how much was paid before proceeding with the inventory giving, rather than merely relying on the script to automatically set the pay amount. Various factors can undermine the intent of those functions that tell a button, for instance, how much to pay when it is clicked.
As with other script learning, I can read through an example vendor script, learn what the various functions do, and understand completely what everything does. Only then I say to myself, time and time again, “Wow, that’s really smart.” The way to write a script is think first what you want it to do. If you have learned all the functions, events and flow control, you can figure out a way to do it. Then, you can find a way to make it more efficient.