HERO = 1;
MONSTER = 2;
BUILDING = 3;
SUMUNIT = 4;
cha = {};
cha[1] =
{
basic =
{
Name = "農(nóng)民", --NPC名字
cha_type = HERO, --NPC模型
},
combat =
{
acquire = 600.00, --主動攻擊范圍
basic_def = 10, --基礎(chǔ)防御
},
};
function SaveTableContent(file, obj)
local szType = type(obj);
print(szType);
if szType == "number" then
file:write(obj);
elseif szType == "string" then
file:write(string.format("%q", obj));
elseif szType == "table" then
--把table的內(nèi)容格式化寫入文件
file:write("{\n");
for i, v in pairs(obj) do
file:write("[");
SaveTableContent(file, i);
file:write("]=\n");
SaveTableContent(file, v);
file:write(", \n");
end
file:write("}\n");
else
error("can't serialize a "..szType);
end
end
function SaveTable()
local file = io.open("e:\\00_00_00_海外組_學(xué)習(xí)\\寫入.txt", "w");
assert(file);
file:write("cha = {}\n");
file:write("cha[1] = \n");
SaveTableContent(file, cha[1]);
file:write("}\n");
file:close();
end
SaveTable();