Did that work when you tried it?tentus wrote:You have an end in the wrong place. I corrected your indentation and it became obvious. Here's what I made:Lua Hal wrote:I'm not sure what you mean, using Lua as a parser.
Also, I re-wrote it trying to make it more efficient, but it still doesn't even do the most simple part.
Code: Select all
function npcparse() npcdata={} data={} for line in love.filesystem.lines("config.txt") do table.insert(data,line) end for i = 1,#data do if string.lower(string.sub(data[i],0,6)) == "spawnx" then spawnx=string.sub(data[i],7) elseif string.lower(string.sub(data[i],0,6)) == "spawny" then spawny=string.sub(data[i],7) elseif string.lower(data[i]) == "newnpc(" then newtab={} for k = i+1,#data do if k == ")" then ending=k end end for h=i+1,ending-1 do if data[h] == "selling(" then temptab={} newtab={temptab} for x=h,#data do if data[x] == ")" then newending=x end end for l = h+1,newending-1 do table.insert(temptab,data[l]) end else for key,score in string.gmatch(data[i], "(%w+);(%d+)") do newtab[key] = score end end end--endfor end--endif end--endnpcparse npcparse() function love.draw() love.graphics.print("X:" .. spawnx,0,12) love.graphics.print("Y: "..spawny,0,12) end end
Code: Select all
function npcparse() npcdata={} data={} for line in love.filesystem.lines("config.txt") do table.insert(data,line) end for i = 1, #data do if string.lower(string.sub(data[i],0,6)) == "spawnx" then spawnx = string.sub(data[i],7) elseif string.lower(string.sub(data[i],0,6)) == "spawny" then spawny = string.sub(data[i],7) elseif string.lower(data[i]) == "newnpc(" then newtab={} for k = i+1,#data do if k == ")" then ending=k end end for h=i+1,ending-1 do if data[h] == "selling(" then temptab={} newtab={temptab} for x=h, #data do if data[x] == ")" then newending = x end end for l = h+1, newending-1 do table.insert(temptab,data[l]) end else for key,score in string.gmatch(data[i], "(%w+);(%d+)") do newtab[key] = score end end end end end end npcparse() function love.draw() love.graphics.print("X:" .. spawnx, 0, 12) love.graphics.print("Y: "..spawny, 0, 12) end
I'm getting a C++ runtime error.
Maybe it wasn't a good idea to save that as my game, Lol.