love.filesystem:setIdenity() error

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
LuaWeaver
Party member
Posts: 183
Joined: Wed Mar 02, 2011 11:15 pm
Location: Ohio, USA

love.filesystem:setIdenity() error

Post 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)
"your actions cause me to infer your ego is the size of three houses" -finley
User avatar
Taehl
Dreaming in associative arrays
Posts: 1025
Joined: Mon Jan 11, 2010 5:07 am
Location: CA, USA
Contact:

Re: love.filesystem:setIdenity() error

Post 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().
Earliest Love2D supporter who can't Love anymore. Let me disable pixel shaders if I don't use them, dammit!
Lenovo Thinkpad X60 Tablet, built like a tank. But not fancy enough for Love2D 0.10.0+.
LuaWeaver
Party member
Posts: 183
Joined: Wed Mar 02, 2011 11:15 pm
Location: Ohio, USA

Re: love.filesystem:setIdenity() error

Post by LuaWeaver »

Oh, thanks. :P. I am using it ROBLOX STYLE. Still, never go there. They locked up like %25 percent of Lua!
"your actions cause me to infer your ego is the size of three houses" -finley
User avatar
leiradel
Party member
Posts: 184
Joined: Thu Mar 11, 2010 3:40 am
Location: Lisbon, Portugal

Re: love.filesystem:setIdenity() error

Post 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.
User avatar
BlackBulletIV
Inner party member
Posts: 1261
Joined: Wed Dec 29, 2010 8:19 pm
Location: Queensland, Australia
Contact:

Re: love.filesystem:setIdenity() error

Post 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)
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Google [Bot] and 0 guests