【问题标题】:Using a variable in a message - Lingo在消息中使用变量 - Lingo
【发布时间】:2015-03-11 16:27:25
【问题描述】:

谁能告诉我是否有一种方法可以让我在一堆代码中使用一个变量,这样代码就可以被循环以向多个对象发送消息?

例如,如果我有 10 个按钮,并且希望每个按钮发送相同命令“sendCommandX”的变体,其中 X 是按钮的编号。

现在我有 10 条单独的消息,每个按钮都调用自己的,比如

on mouseUp
   sendCommand1
end

on mouseUp
   sendCommand2
end

这 10 条 sendCommand# 消息中的每一条都执行相同的操作,只是其中的编号不同。

如果我可以在调用中使用一个变量,那就太好了,这样我就可以有一个可重用的消息。喜欢:

on mouseUp
   sendCommandX (X being the number of the button clicked)
end

然后 sendCommandX 可以在其中使用相同的变量,例如

on sendCommandX
   echo "you clicked button X:
end

【问题讨论】:

    标签: lingo adobe-director


    【解决方案1】:

    将数字作为参数发送:

    -- on Button 1
    on mouseUp
      sendCommand 1
    end
    
    -- on Button 2
    on mouseUp
      sendCommand 2
    end
    
    -- movie script!
    on sendCommand which
      -- use 'which' here, e.g.
      put "You pressed button " & which
    end
    

    我猜你的按钮脚本是演员脚本?

    此代码作为一种行为会更好,因为您只需要一个脚本。但它会像这样正常工作。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-09-28
      • 2016-06-06
      • 1970-01-01
      • 2010-09-30
      • 1970-01-01
      • 2022-01-17
      • 2014-07-17
      • 1970-01-01
      相关资源
      最近更新 更多