lua阅读文件不工作

时间:2018-04-01 05:34:10

标签: arrays lua referrals

我不知道为什么,但我的功能不起作用。

我想创建一个数组playerMonsterplayerMonster的每个节点都是不同的怪物。但是当我尝试每个节点都是一样的 请帮忙。

local monster = {no, power, def, speed, evade, hit, maxhp, spow, potype, lvevo, move1,mov2,smove,pmove, lv, numgame}
local playerMonster = {}

local function readfile()
local path = system.pathForFile("playerpo.txt")
local file = io.open(path, "r")
if file then
    io.input(file)
    for i = 1, player.nummonster do
    monster.no = io.read("*number")
    monster.power = io.read("*number")
    monster.def = io.read("*number")
    monster.speed = io.read("*number")
    monster.evade = io.read("*number")
    monster.hit = io.read("*number")
    monster.maxhp = io.read("*number")
    monster.spow = io.read("*number")
    monster.potype = io.read("*number")
    monster.lvevo = io.read("*number")
    monster.move1 = io.read("*number")
    monster.move2 = io.read("*number")
    monster.smove = io.read("*number")
    monster.pmove = io.read("*number")
    monster.lv = io.read("*number")
    monster.numgame = io.read("*number")
    playerMonster[i] = monster
    end
    for i = 1,5 do
    print(i, playerMonster[i].no)-- all is same
    end
end
file:close()
end

0 个答案:

没有答案