-- frogme.levelgen
set1 = {levelgen:findObjectById(1), levelgen:findObjectById(2)}
set2 = {levelgen:findObjectById(3), levelgen:findObjectById(4)}
set3 = {levelgen:findObjectById(5), levelgen:findObjectById(6)}
set4 = {levelgen:findObjectById(7), levelgen:findObjectById(8)}

setOfAllSets = {set1, set2, set3, set4} --DOES THIS CONTAIN ITSELF?
currentSet = math.random(#setOfAllSets)
lastSet = nil

function changeActiveGoalZone(set)
	if(setOfAllSets[currentSet] ~= nil) then
		lastSet = currentSet
		
		setOfAllSets[currentSet][1]:setTeam(-2)
		setOfAllSets[currentSet][2]:setTeam(-2)
		setOfAllSets[set][1]:setTeam(1)
		setOfAllSets[set][2]:setTeam(2)
		
		currentSet = set
	end
end

function onScoreChanged(scoreChange, teamIndex, player) 
	local roll = lastSet
	repeat 
		roll = math.random(#setOfAllSets) 
		Timer:scheduleOnce(function () changeActiveGoalZone(roll) end, 100) 
	until roll ~= lastSet
end

function main()
	subscribe(Event.ScoreChanged)
	for a = 1, 50 do  --I like a clean console        	logprint(" ")    	end
	currentSet = math.random(#setOfAllSets)
	changeActiveGoalZone(currentSet)
end