有没有人能告诉我有没有办法在一段代码中使用一个变量,这样代码就可以循环发送消息给多个对象?
现在我有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发布于 2011-07-13 04:20:18
将数字作为参数发送:
-- 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我猜你的按钮脚本是演员脚本?
这段代码作为一种行为会更好,因为这样你只需要一个脚本。但是它会像这样工作。
https://stackoverflow.com/questions/6318280
复制相似问题