Help with Oscillation Function in Pulp

Hi, I'm making my first game in Pulp, and I am stuck trying to create an oscillation function for a shield to move up and down repeatedly. The function works perfectly when moving up, but when moving down screen it will delete tiles that are adjacent in the Y direction. I am guessing it is due to the order which the tiles run the code making the tile above already gone by the time the tile below does a check to see if it should make a shield or a tile. The shields are stored as solid sprites.

on shieldMoveUpdate do
	sOriginalY = event.y
	sTargetX = event.x
	sTargetY = event.y
	aboveTargetY = sTargetY
	aboveTargetY--
	aboveTarget = sTargetX,aboveTargetY
	nameAT = name aboveTarget
	belowTargetY = sTargetY
	belowTargetY++
	belowTarget = sTargetX,belowTargetY
	nameBT = name belowTarget
	
	if shieldUp==1 then
		sTargetY -= 1
		tell sTargetX,sTargetY to
			swap "shield"
		end
		if nameBT=="shield" then
			tell sTargetX,sOriginalY to
				swap "shield"
			end
		else
			tell sTargetX,sOriginalY to
				swap "white"
			end
		end
	else
		sTargetY += 1
		if nameAT!="shield" then
			tell sTargetX,sOriginalY to
				swap "white"
			end
		end
		tell sTargetX,sTargetY to
			swap "shield"
		end
		
	end
end

The code run when the shield is moving up is quite different to the code run when the shield is moving down. I would expect them to be more similar if they are simply the opposite of each other.

If the up code is working, try copying that and editing it to do the opposite. If you're still stuck, maybe share a screenshot of what it looks like so it is easy to picture what you are trying to do :slight_smile:

Thanks for checking this out. Sorry, that was iteration like 50 of the code after struggling for a while. I have reverted it back to the original where the moving down code was closer to moving up. The same issue (see GIF) happens in both versions of the code. If the game looks familiar, I'm trying to remake Yars' Revenge to help learn Pulp.

shieldissue

on shieldMoveUpdate do
	sOriginalY = event.y
	sTargetX = event.x
	sTargetY = event.y
	
// checking above Target for when moving downward
	aboveTargetY = sTargetY
	aboveTargetY--
	aboveTarget = sTargetX,aboveTargetY
	nameAT = name aboveTarget
//checking below target for when moving upward
	belowTargetY = sTargetY
	belowTargetY++
	belowTarget = sTargetX,belowTargetY
	nameBT = name belowTarget
	
//note shieldUp is tracked in another script
//first scenario moving upwards
	if shieldUp==1 then
		sTargetY -= 1
		tell sTargetX,sTargetY to
			swap "shield"
		end
// checking if the tile below was a shield and if so replacing the current tile with a shield to simulate movement
		if nameBT=="shield" then
			tell sTargetX,sOriginalY to
				swap "shield"
			end
		else
			tell sTargetX,sOriginalY to
				swap "white"
			end
		end
// second scenario moving downwards		
	else
		sTargetY += 1
		tell sTargetX,sTargetY to
			swap "shield"
		end
// checking if the tile above the current one is a shield to determine if the current position should be a tile or not after movement
		if nameAT=="shield" then
			tell sTargetX,sOriginalY to
				swap "shield"
			end
		else
			tell sTargetX,sOriginalY to
				swap "white"
			end
		end
	end
end

Also, here is a GIF of when the shield is thinner. I'm still getting a weird blip in one spot, but you can see the main issue seems to be when you have consecutive shield tiles in the Y direction

thinshield

I think you are exactly right with this bit :slight_smile:

I am guessing are you calling shieldMoveUpdate on each shield tile. When moving down it seems like you are checking the "aboveTarget" tiles that may have already been swapped.

Because it works correctly when moving up, one way to fix it would be to reverse the order you call the shieldMoveUpdate event on the tiles when the shield moves down.

How are you currently calling the shieldMoveUpdate event on the tiles? If it is with emit that always works through the tiles in a fixed order, so instead you will have to make a loop to do it yourself.