Contacts are true on the beginning of a game

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
ericsantosbr
Prole
Posts: 3
Joined: Tue Feb 12, 2019 3:18 am

Contacts are true on the beginning of a game

Post by ericsantosbr » Wed Oct 23, 2019 1:18 am

Greetings!

I'm trying to create a simple Dinossaur Game clone from the Google Chrome easter egg, but I'm facing a little problem.

As soon as the game starts, a contact callback is activated for a contact that has not been performed yet.

Code: Select all

function compareContacts(a, b, nameA, nameB)
	if (a:getUserData() == nameA or a:getUserData() == nameB and b:getUserData() == nameA or b:getUserData() == nameB) then

		textToPrint = tostring(true)
		contactExists = true

		return true
	else
		return false
	end

end

function beginContact(a, b, coll)
	if (compareContacts(a, b, 'player', 'ground')) then 
		textToPrint = tostring(true)
		contactExists = true
	end
	
	if(compareContacts(a, b, 'player', 'block')) then playerLost = true end

end
The variable playerLost is then set as true, even tho it is first defined as false, and not being touched in the rest of the code.

Any thoughts?

Thank you!

User avatar
raidho36
Party member
Posts: 1932
Joined: Mon Jun 17, 2013 12:00 pm

Re: Contacts are true on the beginning of a game

Post by raidho36 » Wed Oct 23, 2019 5:39 am

A contact may have the bodies touching or not, there's a class function to check this.

Post Reply

Who is online

Users browsing this forum: No registered users and 19 guests