lua 脚本怎么传递参数

脚本一:(随机得到1--5之间的一个数)
x002117_g_scriptId = 002117

math.randomseed(os.time())--os.time()
for i=1,5 do
nRet_rw = math.random(6)
end
脚本二:(为一个函数)
function x002103_OnEventRequest( sceneId, selfId, targetId, eventId )
if nRet_rw==1 then
x002103_MY_ZH=002091
elseif nRet_rw==2 then
x002103_MY_ZH=002101
elseif nRet_rw==3 then
x002103_MY_ZH=002106
elseif nRet_rw==4 then
x002103_MY_ZH=002107
elseif nRet_rw==5 then
x002103_MY_ZH=002108
elseif nRet_rw==6 then
x002103_MY_ZH=002109
end
end
请问:如何把脚本一中获取的nRet_rw的值传递给脚本二中。请以代码的形式说明。谢谢!

第1个回答  2014-07-20
只能调用了,多加一个参数,
for i=1,5 do
nRet_rw = math.random(6)
x002103_OnEventRequest( sceneId, selfId, targetId, eventId,nRet_rw )
end

或者把nRet_rw作为全局变量本回答被网友采纳
第2个回答  2014-07-19
static int ABC(lua_State *L)
{
int n =lua_gettop(L);
double sum =0;
int i;
for (i=1;i<n;i++)
{
sum+=lua_tonumber(L,i);
}
lua_pushnumber(L,sum/n);
lua_pushnumber(L,sum);
return 2;
} lua_register(L, "ABC", ABC);
相似回答