在消息中使用变量 - Lingo

时间:2011-06-11 20:08:50

标签: lingo adobe-director

有人能告诉我是否有办法在一段代码中使用变量,以便代码可以循环以向多个对象发送消息?

例如,如果我有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

1 个答案:

答案 0 :(得分:0)

将号码作为参数发送:

-- 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

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

这段代码会更好,因为那时你只需要一个脚本。但它会像这样工作。