刚开始我在本地调试出错一直觉得是代码语法错误,最后在android设备调试一切OK,原来是我本地编辑器导致的。
方法一:这是一个笨方法,if随机require
package.path=package.path..";/mnt/sdcard/sghqs/?.lua;"
math.randomseed(tostring(os.time()):reverse():sub(1,6))
weijian=math.random(1,3)
if weijian==1 then
require "1"
elseif weijian==2 then
require "2"
elseif weijian==3 then
require "3"
end
方法二:require随机数组
package.path=package.path..";/mnt/sdcard/sghqs/test/?.lua;"
weijian={[1]="1",[2]="2",[3]="3",[4]="4",[5]="5"}
function main()
while true do
math.randomseed(tostring(os.time()):reverse():sub(1,6))
require (weijian[math.random(1,5)])
mSleep(math.random(1000,2000));
ff();
mSleep(math.random(1000,2000));
end
end
方法三:require随机变量
function main()
while true do
package.path=package.path..";/mnt/sdcard/sghqs/test/?.lua;"
math.randomseed(tostring(os.time()):reverse():sub(1,6))
weijian=math.random(1,5)
require (weijian)
mSleep(math.random(1000,5000));
ff();
mSleep(math.random(1000,5000));
end
end