Page 1 of 1

Load Raw Text Files [Resolved]

Posted: Thu Jun 14, 2012 4:25 pm
by Satinxs
I'm pretty new to LUA and of course, to LÖVE, but not new to programming at all. What I can't find out is why I still can't load a raw text file...
I've used the Lua IO, the love.filesystem and all, but still can't make it work...
Any help would be greatly appreciated :)

Here's my latest code, just in case:

Code: Select all

function love.load()

love.graphics.setBackgroundColor(255,255,255)
fontie = love.graphics.newFont(12)
love.graphics.setFont(fontie)

file = love.filesystem.newFile("foo.txt")
s = file:read()
file:close()

end

function love.draw()

love.graphics.setColor(255,255,255,255)
love.graphics.print(typeof(s),100,100)

end

function typeof(var)
    local _type = type(var);
    if(_type ~= "table" and _type ~= "userdata") then
        return _type;
    end
    local _meta = getmetatable(var);
    if(_meta ~= nil and _meta._NAME ~= nil) then
        return _meta._NAME;
    else
        return _type;
    end
end
(The foo.txt exists inside the directory, yes, and it has "Hello world!" inside)

Re: Load Raw Text Files [Unresolved]

Posted: Thu Jun 14, 2012 4:36 pm
by Kadoba
I think you need to open the file in a read mode before you can actually read it.

Code: Select all

function love.load()

love.graphics.setBackgroundColor(255,255,255)
fontie = love.graphics.newFont(12)
love.graphics.setFont(fontie)

file = love.filesystem.newFile("foo.txt")
file:open('r')
s = file:read()
file:close()

end

function love.draw()

Re: Load Raw Text Files [Unresolved]

Posted: Thu Jun 14, 2012 4:37 pm
by Santos
This:

Code: Select all

file = love.filesystem.newFile("foo.txt")
s = file:read()
file:close()
could be replaced with this I think:

Code: Select all

s = love.filesystem.read("foo.txt")
And be sure not to print text the same color as the background! ^^

Code: Select all

function love.draw()

    love.graphics.setColor(0,0,0)
    love.graphics.print(typeof(s),100,100)
    love.graphics.print(s,100,120)

end

Re: Load Raw Text Files [Unresolved]

Posted: Thu Jun 14, 2012 4:40 pm
by Satinxs
Santos wrote:And be sure not to print text the same color as the background! ^^
Daaaaamn, I feel incredibly stupid... Thanks guys :/