Having more than one image on the screen

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
iLuvLove
Prole
Posts: 4
Joined: Thu Nov 24, 2011 5:32 pm

Having more than one image on the screen

Post by iLuvLove »

For some odd reason, I am having trouble displaying more than one image on the screen. Attached is the .love file of my project. Does anyone know what is wrong? Why does it only display one image, and not both?
Attachments
LoveProject.love.zip
The buggy code
(5.96 KiB) Downloaded 104 times
User avatar
Boolsheet
Inner party member
Posts: 780
Joined: Wed Dec 29, 2010 4:57 am
Location: Switzerland

Re: Having more than one image on the screen

Post by Boolsheet »

You're using global variables instead of the values from the Rock instance.

Code: Select all

function Rock:getX()
	return x
end
This will return the value of the global variable x.
You probably want to use self.x here to get the x from the Rock instance.

Code: Select all

function Rock:getX()
	return self.x
end
There are a few more places where self is missing.
Shallow indentations.
iLuvLove
Prole
Posts: 4
Joined: Thu Nov 24, 2011 5:32 pm

Re: Having more than one image on the screen

Post by iLuvLove »

Oh... Thanks. I'm new to lua, so I don't quite have the whole global/local thing figured out yet.
LuaWeaver
Party member
Posts: 183
Joined: Wed Mar 02, 2011 11:15 pm
Location: Ohio, USA

Re: Having more than one image on the screen

Post by LuaWeaver »

Local is just to the function. If I have a function with a local variable, I can reuse that variable later, out of the function.

Code: Select all

function code()
local localCode={"This is a table with a string"}
end
print(localCode[1]) --Results in error.
A global can be used ANYWHERE.

Code: Select all

function code()
return {"This may or may not be a variable when this is called"}
end
globalCode=code()
print(globalCode[1]) --Prints "This may or may not be a variable when this is called"
"your actions cause me to infer your ego is the size of three houses" -finley
iLuvLove
Prole
Posts: 4
Joined: Thu Nov 24, 2011 5:32 pm

Re: Having more than one image on the screen

Post by iLuvLove »

Thanks. I've figured out how the local/global stuff works now though.
Post Reply

Who is online

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