Load Raw Text Files [Resolved]

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
Satinxs
Prole
Posts: 9
Joined: Thu Jun 14, 2012 4:14 pm

Load Raw Text Files [Resolved]

Post 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)
Last edited by Satinxs on Thu Jun 14, 2012 4:41 pm, edited 1 time in total.
User avatar
Kadoba
Party member
Posts: 399
Joined: Mon Jan 10, 2011 8:25 am
Location: Oklahoma

Re: Load Raw Text Files [Unresolved]

Post 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()
Santos
Party member
Posts: 384
Joined: Sat Oct 22, 2011 7:37 am

Re: Load Raw Text Files [Unresolved]

Post 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
User avatar
Satinxs
Prole
Posts: 9
Joined: Thu Jun 14, 2012 4:14 pm

Re: Load Raw Text Files [Unresolved]

Post by Satinxs »

Santos wrote:And be sure not to print text the same color as the background! ^^
Daaaaamn, I feel incredibly stupid... Thanks guys :/
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 7 guests