在消息中使用变量 - Lingo
谁能告诉我是否有办法在一段代码中使用变量,以便可以循环代码向多个对象发送消息?
例如,如果我有 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
Can anyone tell me if there is a way for me to use a variable within a lump of code, so that code can be looped to send messages to multiple objects?
For example, if I have 10 buttons and want each to send a variation of the same command 'sendCommandX', with X being the number of the button.
Right now I have 10 separate messages, and each button calls its own, like
on mouseUp
sendCommand1
end
on mouseUp
sendCommand2
end
Each of these 10 sendCommand# messages do the same thing, just with a different number in them.
It would be great if I could use a variable within the call, so I could have one reusable message. Like:
on mouseUp
sendCommandX (X being the number of the button clicked)
end
and then the sendCommandX could use the same variable within, like
on sendCommandX
echo "you clicked button X:
end
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
发送数字作为参数:
我猜你的按钮脚本是演员脚本?
该代码作为一种行为会更好,因为这样您只需要一个脚本。但像这样就可以正常工作了。
send the number as a parameter:
I guess your button scripts are cast member scripts?
This code would be better as a behavior, because then you'd only need one script. But it will work ok like this.