Page 1 of 1

Contacts are true on the beginning of a game

Posted: Wed Oct 23, 2019 1:18 am
by ericsantosbr
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!

Re: Contacts are true on the beginning of a game

Posted: Wed Oct 23, 2019 5:39 am
by raidho36
A contact may have the bodies touching or not, there's a class function to check this.