【问题标题】:Livecode colorNames() function?Livecode colorNames() 函数?
【发布时间】:2016-04-12 22:05:48
【问题描述】:

我正在尝试编写一个程序来删除名称中带有数字的所有颜色,然后将它们放入一个字段中。我遇到了第 4 行的问题。有什么建议吗?

    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

【问题讨论】:

  • 你的行应该是repeat for each line myLine in choice 并且在 if 语句中你应该检查 myLine 的数字。不要从列表中删除这些行,但如果它们没有数字,则将它们复制到新列表中。无论如何,正如您在我的回答中看到的那样,有一种不同的方法可以做到这一点。

标签: livecode


【解决方案1】:

看起来您忘记指定变量 -- tColor -- 来表示您选择变量中的每一行。此外,当对每个都使用重复时,最好构建一个新的结果列表,而不是尝试修改原始变量(选择)。

尝试类似:

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

还请注意,您实际上需要写出“或”(假设您正在尝试这样做)——LiveCode 不使用该运算符的符号。

【讨论】:

    【解决方案2】:

    这一行将所有不包含数字的颜色名称放入变量myList

    filter the colorNames without "*[0-9]*" into myList
    

    【讨论】:

    • 这个方法不错,但是语法不正确。您需要在过滤之前将颜色名称放入 MyList。
    • 对不起,你是对的。当我浏览回复时,我忘记了“进入”修饰符。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多