I am attempting to get the following script to work in my game. I have an animated set of tiles which is meant to look like a spike popping in and out of the ground. I only want this spike to harm the hero when it is out of the ground so I have made this script:
script, harmSpike, begin
if(read map block (hero x, hero y, 0) == 183) then(
loseHealth
)
end
This script is called within a while loop executing every tick but when I tested it out nothing seems to happen.
I have tested this with non-animated tiles changing the value 183 to 23 which would be the non-animated spike tile and it works fine. I'm not sure why this doesn't work for the animated tile. Am I missing something? Also I am using the animation set 0.
EDIT: Figured it out! I just added on this "+ get tile animation offset (animation pattern, layer)" to account for the animation frame if anyone was wondering.
Thank you. So using the code you gave I was able to reveal that the animation tiles were always equal to 181, not 183. This is because the number does not change based on the animation frame but instead is based on the animation's start tile. So is there a way that I can do what I originally intended using something like read map block since the animation thing didn't work the way I had thought?
Last edited by sheamkennedy on Tue May 19, 2015 12:52 am, edited 1 time in total.
read map block(x, y, 0) + get tile animation offset(0, 0) == 183
(or whatever the correct layer and animation pattern numbers are), which could conceivably break if you create more tile animations (e.g. one numbered 183).
Using hero X and hero Y isn't really ideal for testing the tile the hero is on if they can be partway between tiles, as it returns the tile to the top left rather than the one they're mainly over. Since you're testing every tick rather than just using an each-step script I assume you do want to be able to catch the hero midstep. For that, use instead: