Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Scheme help (unbound error)
#1
See below.
I get a g1Layer is unbound error, despite the fact that (non-empty) text is being passed in to the g1Text parameter.
The intent is to create a text layer and then position a comic book style talk bubble underneath it.

Can you place conditionals inside the local variable declaration area in scheme? How do I prevent bubbles/text layer being created if the user passes in a blank string?


Code:
  (script-fu-register
    "script-fu-talk-bubble"                        ;func name
    "Diag Bubble"                                  ;menu label
    "Creates a dialog bubble"              ;description
    "-0-"                             ;author
    "copyright 2017, -0-"        ;copyright notice
    "November 10, 2017"                          ;date created
    ""                     ;image type that the script works on
    SF-IMAGE       "Input image" 0
    SF-DRAWABLE    "Input drawable" 0
    SF-STRING      "g1Text"          "**"   ;a string variable

    SF-FONT        "Font"          "Sans"    ;a font variable
    SF-ADJUSTMENT  "Font size"     '(32 1 1000 1 10 0 1) ;a spin-button
    SF-COLOR       "gText Color"    '(250 104 255)     ;color variable
    SF-COLOR       "mText Color"    '(0 0 0)     ;color variable
    SF-COLOR       "dText Color"    '(208 59 59)     ;color variable

    SF-COLOR      "Bubble color"   '(255 255 255)
    SF-TOGGLE     _"createBubbles"          TRUE
  )
  (script-fu-menu-register "script-fu-talk-bubble" "<Image>/Image/CreateLayers")
  
 (define (script-fu-talk-bubble aimg adraw g1Text inFont inFontSize textColorG textColorM textColorD bubbleColor createBubbles)
    
    (gimp-context-set-foreground textColorG)
    (gimp-context-set-background bubbleColor)
    
    (let*
        (
            (theImageWidth  (car (gimp-drawable-width  adraw) ) )
            (theImage aimg)
            (theImageHeight (car (gimp-drawable-height adraw) ) )
            (theImageX)
            (theImageY)
            (theText)     
            (theTextBubble)        
            (theBuffer) 
            (relLocX 12)
            (space 32)
            (g1Len (string-length g1Text))        

            (set! theImageWidth   (car (gimp-drawable-width  adraw) ) )
            (set! theImageHeight  (car (gimp-drawable-height adraw) ) )    
            
            (if (> g1Len 0)
                (g1Layer
                    (car
                         (gimp-text-layer-new
                          aimg
                          g1Text
                          inFont
                          inFontSize
                          PIXELS
                         )
                     )
                )
            )
                                              
        ) 
    

        (if (= createBubbles TRUE)
        (         
            (gimp-image-add-layer theImage g1Layer 0)
            
            (gimp-text-layer-set-color m1Layer textColorM)
            
            (gimp-layer-set-offsets g1Layer 12 relLocX)
            (set! relLocX (+ (+ 12 inFontSize) space))

            
            (set! theImageWidth   (car (gimp-drawable-width  g1Layer) ) )
            (set! theImageHeight  (car (gimp-drawable-height g1Layer) ) )         
            (set! theImageX   (car (gimp-drawable-offsets  g1Layer) ) )
            (set! theImageY  (cadr (gimp-drawable-offsets g1Layer) ) )         
         

            (set! theTextBubble
                    (car
                          (gimp-image-select-round-rectangle
                          theImage 0 theImageX theImageY theImageWidth theImageHeight 12 12)
                    )            
            )    
        
            (gimp-selection-grow theImage 4)
            (gimp-context-set-foreground bubbleColor)

            (gimp-edit-bucket-fill bubbleLayer 0 0 100 0 0 0 0 )

            (gimp-layer-set-opacity bubbleLayer 90)         
         
        )) 
    )
  )         
Reply


Messages In This Thread
Scheme help (unbound error) - by ssallen - 12-21-2017, 08:31 PM
RE: Scheme help (unbound error) - by Ofnuts - 12-21-2017, 09:25 PM
RE: Scheme help (unbound error) - by ssallen - 12-21-2017, 09:41 PM
RE: Scheme help (unbound error) - by Ofnuts - 12-21-2017, 10:47 PM

Forum Jump: