Page 1 of 1

love.filesystem:setIdenity() error

Posted: Sun Mar 27, 2011 8:54 pm
by LuaWeaver
Whenever I use this code to try and understand love.filesystem, it creates an error.

Code: Select all

local text="If this shows, it did not work."

function love.load()
	love.filesystem:setIdentity("TEST") --Right here! It says "main.lua:4: Calling 'setIdentity' on bad self. (string expected, got table)" "TEST" is a table I guess?
	local h=love.filesystem:newFile("text.txt")
	h:open("w")
	h:write("If this shows, it worked")
	h:close()
	h:open("r")
	text=h:read()
end

function love.draw()
	love.graphics:print(text, 20, 20)
end
This is all the code. Again, here is the error. main.lua:4: Calling 'setIdentity' on bad self. (string expected, got table)

Re: love.filesystem:setIdenity() error

Posted: Sun Mar 27, 2011 8:57 pm
by Taehl
You're calling it wrong. It should be love.filesystem.setIdentity(name). Note how it uses only periods, not colons. Colons, in Lua, mean something completely different. Likewise, don't use a colon for love.graphics.print().

Re: love.filesystem:setIdenity() error

Posted: Sun Mar 27, 2011 9:00 pm
by LuaWeaver
Oh, thanks. :P. I am using it ROBLOX STYLE. Still, never go there. They locked up like %25 percent of Lua!

Re: love.filesystem:setIdenity() error

Posted: Sun Mar 27, 2011 9:19 pm
by leiradel
Just to help LuaWeaver better understand the difference.

This code calls the setIdentity function which lives in the filesystem table which in turn lives in the love table which is a global variable (meaning it lives in the globals table):

Code: Select all

love.filesystem.setIdentity(name)
This code calls the setIdentity function the same way as described before, but adds the value in the left of the colon as an automatic first parameter to the call:

Code: Select all

love.filesystem:setIdentity(name)
which is identical to

Code: Select all

love.filesystem.setIdentity(filesystem, name)
That's way the error says it was expecting a string for the first parameter but found a table instead.

Re: love.filesystem:setIdenity() error

Posted: Sun Mar 27, 2011 11:15 pm
by BlackBulletIV
Rule of thumb: If it's under love.*, use a dot. If it's something created via love.*.new*, use a colon.
leiradel wrote:

Code: Select all

love.filesystem.setIdentity(filesystem, name)
More precisely:

Code: Select all

love.filesystem.setIdentity(love.filesystem, name)