Gimp-Forum.net

Full Version: I need help to declare a variable or a function in scheme
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I'm trying to set a variable or a function but nothing is working, I always got "Illegal function", or "unbound variable", or whatnot

A screenshot about what I try to do
Having a variable will allow me to only input the variable in the other lines (in red), unless my thinking is wrong (that's also something to take in count).
[attachment=10755]

Here is the code, if I understood (while (> i 0) where i is a variable and I try to catch when i is equal to 1
How can I catch that number to change the variable depending that number?

Code:
(while (> i 0)
      (set! image (vector-ref (cadr (gimp-image-list)) (- i 1)))
      (set! newFileName (string-append inDir
              pathchar inFileName
              (substring "0000000" (string-length
              (number->string (+ inFileNumber i))))
              (number->string (+ inFileNumber i)) saveString))

;;;;;;;;;;;;;;;;;  START to set my variable isInteractive ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

     (set! isInteractive (if ((equal? i 1) RUN-INTERACTIVE)
                                 (else (RUN-WITH-LAST-VALS))))

;;;;;;;;;;;;;;;;;;;;;;;;;   END ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

      (cond
        ((equal? saveString ".webp")
                            
           (file-webp-save2 isInteractive ;;;; << once set isInteractive should switch to RUN-INTERACTIVE or RUN-WITH-LAST-VALS depending the value of i
                      image
                      (car (gimp-layer-new-from-visible image image "export"))
                      newFileName
                      newFileName
                      1    ; preset 0=default 1=pic 2=photo 3=drawing 4=icon 5=text
                      0    ; Use lossless encoding (0/1)
                      90   ; Quality of the image (0 <= quality <= 100)
                      90   ; alpha-quality  0<>100
                      0    ; Use layers for animation (0/1)
                      0    ; Loop animation infinitely (0/1)
                      0    ; Minimize animation size (0/1)
                      0    ; Maximum distance between key-frames (>=0)
                      0    ; Toggle saving exif data (0/1)
                      0    ; Toggle saving iptc data (0/1) works only if save XMP data is also checked ?
                      0    ; Toggle saving xmp data (0/1)
                      0    ; Toggle saving thumbnail (0/1)
                      0    ; Delay to use when timestamps are not available or forced
                      0    ; Force delay on all frames (0/1)

          ))

I did try with (cond instead of (if I tried also starting with (begin (set! nothing is working, and let's face it, I'm also overwhelmed by the number of parenthesis Huh
try VSC, free in linux, it's great, colored brackets for scheme help a lot.

this code will print 'value = 1' in the error console.
change #t to #f and it'll print 'value = 2'

Code:
(let*

(
   (value 0)
 )

   (set! value (if #t 1 2))
 
   (gimp-message (string-append "value = " (number->string value)))
)

maybe try: (set! isInteractive (if (equal? i 1) RUN-INTERACTIVE RUN-WITH-LAST-VALS))

I'd probably do this though, out of habit.


Code:
(if (= i 1) (set! isInteractive RUN-INTERACTIVE)
 (set! isInteractive RUN-WITH-LAST-VALS))
Thanks @pixelmixer, but no, that was not the problem Wink

I found out why it was not working, and also I found out that I i comparison with a hard number was also wrong

First I did not declare isInteractive in the top list of variable declaration, because I over looked this part where there is (let* (yeah I know... I should have paid attention)
Then it was working backward, because of i comparing with 1 or 2, because I did not see i that i was the list of opened image misused by 1 on each loop, as I thought it was and ordered count number starting by 0 or 1, then I understood that I needed to save the original first count of the images somewhere for comparison, thus I created j which keep the full original number of the images in the list and the everything went according to the plan  Big Grin

and tada... YEaaaa, all tested and working super nicely (it looks so simple now, but what a struggle  Big Grin Big Grin  Big Grin )

[attachment=10760]

EDIT:
What a disappointment this script language...
it runs RUN-WITH-LAST-VALS not the way as I expected,
it seems to take in count the last values you did exported using File > Export... or the original quality of the JPG, I said "or", because it seems to be inconsistent. (need more tests to find out where come those values)

In all case it does not take in count the last value of RUN-INTERACTIVE the first time the script is launched, NOR the hard coded values I did input in the script

Also, if you add some more opened images after running the script, the next time you re-run the script, all added images AFTER the script first run will run in INTERACTIVE > you do need to refresh the script for the added images to not run interactive...

I feel I did all that for nothing, I' thinking I'd just keep my first version with setting in the code itself, this version is consistent and does follow the settings coded
OK, I don't give up... yet.

I might have found a solution, but it will be ugly, and I'm kind of good at being ugly  Big Grin
But I do need to know how to add the "Tips" part in a scm like in Python, because people will never remember some "conditions"

[attachment=10761]

Some one knows how to do it?
the highs and lows of programming! Smile
(12-08-2023, 11:51 AM)pixelmixer Wrote: [ -> ]the highs and lows of programming!  Smile

Indeed!  Big Grin  

Anyway it's finished, I'm quite happy as it works fine, but I cannot find how to put the "Tips" or comment above  Undecided