Interacting with adjacent tiles

I'm trying to make a basic Zelda clone and I'm having some trouble figuring out how implement an "attack" action using the confirm function.

I've got the player to draw a sword swipe on the appropriate adjacent tile when pressing A, but I can't seem to get a sprite to disappear after being "attacked." Here's the script for the sprite:

on destroy do
	positionX = event.x
	positionY = event.y
	position = name positionX,positionY
	if position=="slashLeft" then
		swap "white"
	end
end

When performing the attack action, the player does "emit destroy" if that helps.

And here's the whole "game":
ZELDA CLONE TEST.zip (3.1 KB)

I took a look at your code and I noted a few issues. First, what I did was start logging to make sure things are executing. For instance,

on destroy do
	positionX = event.x
	positionY = event.y
	position = name positionX,positionY	
	log "destroying {positionX}, {positionY}"

and so on. Just a strategy to keep in mind for the future.

The first issue I found was:

emit destroy

This should be

emit "destroy"

Events/functions still have to be passed as strings of their names.

Second, note that emit emits to every single tile that supports that event. So in your case, hitting ANY hazard tile emits to ALL of them telling them they're destroyed.

I think you're on the right track otherwise!

1 Like

Thank you! I can't believe I forgot the quotation marks!

And I forgot about emit calling every tile, so I changed the player's script to the following...

		tell atk_posX,atk_posY to
		  swap "white"
		end

.. and that did the trick. I'm sure there's a better way of doing all of this. Still new! Thanks again.

1 Like