2

I am trying to write a program that gets rid of all of the colors with numbers in their names and then puts them into a field. I am running into problems with line 4. Any suggestions?

    on mouseup
       global choice
       put colorNames() into choice
       repeat for each line in choice
         if tcolor1 contains "1" || "2" then
             delete tcolor1 from choice
         end if
       end repeat
       put choice into fld "color list"
    end mouseup
hopeitup
  • 23
  • 2
  • Your line should read `repeat for each line myLine in choice` and in the if-statement you should check myLine for numbers. Don't delete the lines from your list but copy the lines to a new list if they have no numbers. Anyway, as you can see in my answer, there is a different way to do this. – Mark Apr 12 '16 at 23:03

2 Answers2

1

Looks like you forgot to specify the variable -- tColor -- to represent each line in your choice variable. Also, when using repeat for each, you're better off building a new list of the results you want, rather than trying to modify the original variable (choice).

Try something like:

on mouseUp
   global choice
   put colorNames() into temp
   repeat for each line tColor in temp
      if tColor contains "1" or tColor contains "2" then next repeat -- SKIP UNWANTED RESULTS
      put tColor & return after myColorList -- BUILD A NEW LIST
   end repeat
   delete last char of myColorList -- REMOVE THE LAST RETURN CHARACTER
   put myColorList into choice
   put myColorList into fld "color list"
end mouseUp

Also notice you need to actually write out "or" (assuming that's what you're trying do ) -- LiveCode doesn't use a symbol for that operator.

Scott Rossi
  • 885
  • 5
  • 6
0

This line puts all color names that don't contain numbers into variable myList:

filter the colorNames without "*[0-9]*" into myList
Mark
  • 2,380
  • 11
  • 29
  • 49
  • This is a good method but the syntax is incorrect. You'll want to put the colornames into MyList before filtering. – Jacque Apr 13 '16 at 07:24
  • 1
    Sorry, you're correct. I forgot about the "into" modifier when I skimmed the response. – Jacque Apr 13 '16 at 17:39