Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
reading file till end of it — Gideros Forum

reading file till end of it

emreemre Member
edited June 2013 in Roadmap
Hii I try to read a file and generate game data from it.
File game-1.txt contains lines like:

10 40 2
150 200 3
...

The code I try to load it is following:
Points = Core.class(Sprite)
 
function Points:init(gameLevel)
	self.gameLevel = gameLevel
	self.points = {}
	self.loadPoints();
end
 
function Points:loadPoints()
	file = io.open("game-" .. self.gameLevel .. ".txt", "r")
 
	local line = file:read("*line")
 
    while line~=nil do
		local splited = line.split(" ")
		self.points[#self.points + 1] = {x = splited[0], y = splited[1], cc = splited[2]}
        line = file:read("*line")
    end 	
end
I get an error:
points.lua:10: attempt to index local 'self' (a nil value)
stack traceback:
points.lua:10: in function 'loadPoints'
points.lua:6: in function 'init'
[string "property.lua"]:52: in function '__new'
[string "property.lua"]:59: in function 'new'
main.lua:17: in main chunk

Thanks for your help.

Comments

Sign In or Register to comment.