cof*_*aga 1 c# lua luainterface
我正在使用LuaInterface和C#,并且已经正确设置了所有内容.
我想要做的是当脚本使用lua.DoFile()启动时,该脚本可以访问我可以发送的Player对象...
现行代码:
public static void RunQuest(string LuaScriptPath, QPlayer Player)
{
QMain.lua.DoFile(LuaScriptPath);
}
Run Code Online (Sandbox Code Playgroud)
但正如您所看到的,脚本将无法访问Player对象.
我看到两个选择.第一个是让你的玩家成为Lua的全局变量:
QMain.lua['player'] = Player
Run Code Online (Sandbox Code Playgroud)
然后,您将能够访问player您的脚本
第二个选项是让脚本定义一个接受播放器作为参数的函数.因此,如果您当前的脚本...code...现在包含它将包含:
function RunQuest(player)
...code...
end
Run Code Online (Sandbox Code Playgroud)
你的C#代码看起来像这样:
public static void RunQuest(string LuaScriptPath, QPlayer Player)
{
QMain.lua.DoFile(LuaScriptPath); // this will not actually run anything, just define a function
QMain.lua.GetFunction('RunQuest').Call(player);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1681 次 |
| 最近记录: |