Booleans and operator help

Ok I’m here again. I need help to accomplish this. I have been since yesterday night and I could not. I am blocked. In my second game the controls are zoom in zoom out to move objects. There will only be three zoom in and three zoom out positions to play. The problem I have is with the count of the zoom taps and the positions of the objects. I want them to only open and close at specific positions. I can’t make this happen.

Here the code:

--zoom out/in
local function zoomButtonsTouch( event )

	if ( event.phase == "began" ) then
    
		zoomOutTap = zoomOutTap
		zoomInTap  = zoomInTap


		if ( event.target.id == "1" ) and ( canZoomOut == true)      then
      
			print( "Zoom out taps", zoomOutTap )
			if (zoomOutTap > 1) then
				zoomOutTap = zoomOutTap - 1
			        controls.objectZoomOut()
			else
				canZoomOut = false; canZoomIn = true; zoomOutTap = 4
				print( "No more zoom out!" )
		        end
		elseif ( event.target.id == "2" ) and ( canZoomIn == true) then
      
			print( "Zoom out taps", zoomInTap )
			if (zoomInTap > 1) then
				zoomInTap = zoomInTap - 1
				controls.objectZoomIn()
			else
				canZoomIn = false; canZoomOut = true; zoomInTap = 4
				print( "No more zoom! in" )
			end
		end

	end
	return true
end

After that “began” line why are you doing this?

zoomOutTap = zoomOutTap
zoomInTap  = zoomInTap

I don’t know the rest of the code but those might be the cause. What are those supposed to do?

You’re basically resetting the taps every time it’s touched. You would need to keep track of the taps outside, so something like this can work:

if ( event.phase == "began" ) then


	if ( event.target.id == "1" ) and ( canZoomOut == true)      then
  
		print( "Zoom out taps", event.target.zoomOutTap )
		if (event.target.zoomOutTap > 1) then
			event.target.zoomOutTap = event.target.zoomOutTap - 1
		        controls.objectZoomOut()
		else
			canZoomOut = false; canZoomIn = true; event.target.zoomOutTap = 4
			print( "No more zoom out!" )
	        end
	elseif ( event.target.id == "2" ) and ( canZoomIn == true) then
  
		print( "Zoom out taps", zoomInTap )
		if (event.target.zoomInTap > 1) then
			event.target.zoomInTap = event.target.zoomInTap - 1
			controls.objectZoomIn()
		else
			canZoomIn = false; canZoomOut = true; event.target.zoomInTap = 4
			print( "No more zoom! in" )
		end
	end

end
return true

I understand that I did not know how to explain, sorry. Those variables are there because it is the only way I have to capture the value in which the player left the respective taps.

Objects are going to have three positions, imagine it like this, big, medium and small. What I want is that if I am in the medium pressing zoom in, I can zoom out from the same position without truncating the values, causing them to go to another x or y value changing the default positions

@Siu yes, zoom taps variables are forward declared

I put together something like this. Can you check if that’s what you’re after?

--zoom out/in
local startingZoomOutTap = 3
local startingZoomInTap = 3

local zoomOutTap = startingZoomOutTap
local zoomInTap = startingZoomInTap

local canZoomIn = true
local canZoomOut = true

local function zoomButtonsTouch( event )

	if ( event.phase == "began" ) then
		print "began"
    	print ("zoomOutTap", zoomOutTap, "zoomInTap", zoomInTap)

		if ( event.target.id == "zoomOut" and canZoomOut)      then
      
			print( "Zoom out taps", zoomOutTap )
			if (zoomOutTap > 1) then
				zoomOutTap = zoomOutTap - 1
				print "ZOOM OUT"
			    --controls.objectZoomOut()
			else
				canZoomOut = false
				canZoomIn = true
				zoomOutTap = startingZoomOutTap
				print( "No more zoom out!" )
		    end
		elseif (event.target.id == "zoomIn"  and canZoomIn) then      
			print( "Zoom out taps", zoomInTap )
			if (zoomInTap > 1) then
				zoomInTap = zoomInTap - 1
				print "ZOOM IN"
				--controls.objectZoomIn()
			else
				canZoomIn = false
				canZoomOut = true
				zoomInTap = startingZoomInTap
				print( "No more zoom in!" )
			end
		end

	end
	return true
end

local buttonZoomOut = display.newRect( 200, 200, 100, 100 )
buttonZoomOut.id = "zoomOut"
buttonZoomOut:addEventListener( "touch", zoomButtonsTouch )

local buttonZoomIn = display.newRect( 600, 600, 100, 100 )
buttonZoomIn.id = "zoomIn"
buttonZoomIn:addEventListener( "touch", zoomButtonsTouch )
1 Like

@bgmadclown almost exact, I have to adapt it to my code and I let you know. Thanks for your help!

1 Like