You need to define the image and drawable area when registering your script. For example:
(script-fu-register "script-fu-some-handy-function"
_"_Handy function..."
_"Does something handy for your image."
"Michael T <username@domain.com>"
"Michael T"
"24/09/2022"
"*"
SF-IMAGE "Input image" 0
SF-DRAWABLE "Input drawable" 0
)
Then, when you need to use the image, you will just type "image" to use the referenced image.
(define (script-fu-some-handy-function image drawable)
(define width (car(gimp-image-width image)))
(define height (car(gimp-image-height image)))
(define newLayer (gimp-layer-new image width height 1 "Black" 100 0))
(define newLayerIndex (car newLayer))
(gimp-image-insert-layer image newLayerIndex 0 0)
(gimp-context-set-foreground '(0 0 0))
)
Notice how we define the variable in the function definition, otherwise that variable won't work within the definition.