将对象从 C# 传递给 Lua 脚本
我正在使用 LuaInterface 和 C#,并且所有设置都正确。
我想要做的是,当使用 lua.DoFile() 启动脚本时,该脚本可以访问我可以发送的 Player 对象...
当前代码:
public static void RunQuest(string LuaScriptPath, QPlayer Player)
{
QMain.lua.DoFile(LuaScriptPath);
}
但如您所见,脚本不会可以访问 Player 对象。
I am using LuaInterface with C#, and have got everything set up correctly.
What I want to be able to do is that when the script is started using lua.DoFile(), that the script has access to a Player object that I can send...
Current Code:
public static void RunQuest(string LuaScriptPath, QPlayer Player)
{
QMain.lua.DoFile(LuaScriptPath);
}
But as you can see the script will not have access to the Player object.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我看到两个选择。第一个是让你的播放器成为 Lua 的全局变量:
然后你就可以在脚本中访问
player
第二个选项是让脚本定义一个接受播放器作为参数的函数。因此,如果您当前的脚本包含
...code...
现在它将包含:并且您的 C# 代码将如下所示:
I see two options. The first one is to make your player a global variable for Lua:
Then you'll be able to access
player
in your scriptThe second option is to have the script define a function accepting player as parameter. So if your current script contains
...code...
now it will contain:and your C# code will look something like this: