Can't get the result

≈Hi Guys,

Could anyone shed some light on why I’m struggling to get the result and store it as a variable, in the snippet below? the text result sometimes shows up in the result window in Script Debugger.

set someScale to {“dorian”, “mixolydian”, “lydian”, “blues”, “phrygian”}
–make a list with numbers
set theScale to choose from list someScale
if theScale = {“dorian”} then return {“1, 2, 3, 4, 7”} as list
if theScale = {“mixolydian”} then return “2, 3, 4, 6, 7”
if theScale = {“lydian”} then return {“3 4 5 6 7”}
if theScale = {“blues”} then return “4, 5, 6, 7, 8”
if theScale = {“phrygian”} then return " 4, 5, 6, 7, 8"

When, exactly? And what result are you expecting?

The way your script is written:

choosing dorian returns {“1, 2, 3, 4, 7”} as list – a list containing a single string separated by comma and space.

choosing mixolydian returns “2, 3, 4, 6, 7” – a single string separated by comma and space.

choosing lydian returns {“3 4 5 6 7”} - a list containing a single string separated by space but no comma.

choosing blues returns “4, 5, 6, 7, 8” – a single string separated by comma and space.

choosing phrygian returns " 4, 5, 6, 7, 8" – a single string separated by comma and space but beginning with a space.

So, depending on your user’s choice, you have four differently formatted outputs: only mixolydian and blues are consistent.

Try to understand the differences between these inconsistent results. From that, you may begin to understand why it is important for you to be consistent when you write your scripts and set your variables. Look at each result and decide how the rest of your script will handle the output from your choose from list command.

Then check again: is “blues” the same as “phrygian”? Your script suggests that it is, although the returned value from “phrygian” has an extra space at the beginning. I don’t know - as I’ve said before, I only have a very limited understanding of musical theory.

Discipline yourself: check for your own inconsistencies and think sequentially. Read what you type. Stand back from it. Think about what might be wrong.

Start with small chunks. Make sure they work as chunks before you start stringing them together. Understand what you are doing and why you are doing it.

Don’t just copy stuff and assume that it will work. Read it, understand it, think about why it might not work.

Don’t do complicated stuff before you really understand how to do simple stuff.

Never give up…

I was just trying different options, i couldnt assign any of the results to a variable to be used later on in the script

Did you try:

set someScale to {"dorian", "mixolydian", "lydian", "blues", "phrygian"}
--make a list with numbers
set theScale to choose from list someScale
if theScale = {"dorian"} then set SomeVariable to {"1, 2, 3, 4, 7"} as list
if theScale = {"mixolydian"} then set SomeVariable to "2, 3, 4, 6, 7"
--etc etc

Yes, it didnt work but for some reason it worked after opening it in a fresh script