A custom function in google docs is tied to a specific document (and thus can only be used in that document).
It must therefore be created with that document's scrip edit (Tools -> Script Editor). Once saved, it can then be used like any other regular spreadsheet formula.