相同的Lua代码, Lua -l Missionscore 的时候,解释不一样, 如果在Windows 平台下正常, 那么在LINUX下可能不正常。
所以, 在不同的平台下, 需要 Lua -l file 对代码进行确认
require('LuaXml')
GMissionSet = nil -- 任务列表
-- 读取XML 配置文件
function LoadMissionxmlfile()
local missiontables = {}
-- 加载任务文件
local xfile = xml.load("sheet.xml")
if nil == xfile then
-- gl:_writelog("read file error. check sheet.xml")
return nil
else
if type(xfile) ~= "table" or #xfile == 0 then
-- gl:_writelog("read file contents error.")
return nil
end
print(#xfile)
for idx = 1, #xfile do
local segment = xfile[idx]
local mission = {}
mission = {ID = 0, Sub = 0, Subv = 0, Desc = "", Per = 0, Val = 0}
local item = find(segment,"Sheet")
if nil == item then
local str = string.format("no find Sheet tag. tag of index = %d.", idx)
else
local id = find(item, "ID")
if nil == id or type(id) ~= "table" or #id == 0 then
local str = string.format("Invalid ID On Sheet. tag of index = %d.", idx)
print(str)
else
mission.ID = tonumber(id[1])
end
local sub = find(item, "Sub")
if nil == sub or type(sub) ~= "table" or #sub == 0 then
local str = string.format("Invalid Sub On Sheet, tag of index = %d.", idx)
print(str)
else
mission.Sub = tonumber(sub[1])
end
local subv = find(item, "Subv")
if nil == subv or type(subv) ~= "table" or #subv == 0 then
local str = string.format("Invalid Subv On Sheet, tag of index = %d.", idx)
print(str)
else
mission.Subv = tonumber(subv[1])
end
local desc = {}
local per = find(item, "Per")
if nil == per or type(per) ~= "table" or #per == 0 then
local str = string.format("Invalid Per On Sheet. tag of index = %d.", idx)
print(str)
else
mission.Per = tonumber(per[1])
end
local val = find(item, "Val")
if nil == val or type(val) ~= "table" or #val == 0 then
local str = string.format("Invalid Val On Sheet. tag of index = %d.", idx)
print(str)
else
mission.Val = tonumber(val[1])
end
end
local msg = string.format("mission = {ID = %d, Sub = %d, Subv = %d, Desc = '', Per = %d, Val = %d}", mission.ID, mission.Sub, mission.Subv ,mission.Per, mission.Val)
print(msg)
if mission.ID ~= 0 then
table.insert(missiontables, mission)
end
end
end
return missiontables;
end
-- 获取总的百分比
function CalcTotalPer( tables)
local total = nil
if type(tables) ~= "table" or 0 == table.getn(tables)then
gl:_writelog("Invalid Input Parameter In CalcTotalPer function.")
else
taltal = 0
for idx = 1, idx <= #tables do
local item = {}
item = tables[idx]
total = total + item.Per
end
end
if total <= 0 then
total = nil
end
return total
end
-- 获取随机到的数据(游标移动方式)
function GetRandomItem( rand, tables)
local item = {}
local per = 0
if type(tables) ~= "table" or 0 == table.getn(tables)then
gl:_writelog("Invalid Input Parameter In GetRandomItem function.")
else
for idx = 1, #tables do
item = tables[idx]
per = per + item.Per
if per >= rand then
break
end
end
end
return item
end
----
GMissionSet = LoadMissionxmlfile()
需要用到。 LuaXml_lib库
阅读(1718) | 评论(1) | 转发(0) |