jeudi 25 juin 2020

Limited IF-Statements in AppleScript?

I have been developing an AppleScript for several months now and reached around 6,000 lines of code.

It’s function is to run with Automator which receives the contents from the clipboard which are copied lines from a spreadsheet. Then, it writes these contents to various global variables.

The global variables are modified throughout and extensive logic tree in the main function and finally written back to the clipboard with an output function:

global SomeGlobalVariables

on OutputFunction()
    
    #write global variables to clipboard
    
end OutputFunction

on InputFunction(input, parameters)
    
    #write clipboard to global variables
    
end InputFunction

#main function

on run {input, parameters}
    
    InputFunction(input, parameters)
    
    if globalVariable1 = "Test" then

        #Code with many IF-Statements modifying global variables

    else if globalVariable1 = "Test2" then

        #Code with many IF-Statements modifying global variables
        #if globalVariable1 = "abc" then beep


    #... 
    #Code with many IF-Statements modifying global variables
    #... 
    #... 


    end if
    
end run

Now, I have run into a very peculiar problem:

Once I get beyond a certain amount of IF-Statements in the main function the code throws an error before I reach end run.

For example, if globalVariable1 is „Test“ the code works just fine at first. But when I later on modify the section for „Test2“ by adding some random IF-Statements like

if globalVariable1 = "abc" then beep

I get an error message before end run. This is even though the „Test2“-section will never be processed because globalVariable1 stays „Test“ all the time.

The error messages I receive are rather random varying wildly depending on how many random IF-Statements I put to the code. Mostly they state that something cannot be converted to number/text/…

I have never heard such a thing before but is there a limit on IF-Statement I can have in my code or an obvious flaw that would explain the behavior?

Thank you!

Aucun commentaire:

Enregistrer un commentaire