Help using Read Map Block for animation

Ask and answer questions about making games and related topics. Unrelated topics go in that other forum.

Moderators: marionline, SDHawk

Post Reply
User avatar
sheamkennedy
Liquid Metal Slime
Posts: 1110
Joined: Mon Sep 16, 2013 9:29 pm
Location: Tama-shi, Tokyo, Japan
Contact:

Help using Read Map Block for animation

Post by sheamkennedy »

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:

Code: Select all

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.
⊕ P E R S O N A L M U S I C: https://open.spotify.com/album/6fEo3fCm5C3XhtFRflfANr
� C O L L A B M U S I C: https://dustpuppets.bandcamp.com/releases
User avatar
Gizmog
Metal King Slime
Posts: 2615
Joined: Tue Feb 19, 2008 5:41 am

Post by Gizmog »

Well, one way to diagnose what's happening is to throw in a ShowValue.

Code: Select all

script, harmSpike, begin
  variable (HerosTile)
  HerosTile := ReadMapBlock (HeroX,HeroY,0)
  ShowValue (HerosTile)
  if (HerosTile == 183) then( 
      loseHealth 
  ) 
end
That way you could visually verify whether or not the number was actually changing when the tile animates.
User avatar
sheamkennedy
Liquid Metal Slime
Posts: 1110
Joined: Mon Sep 16, 2013 9:29 pm
Location: Tama-shi, Tokyo, Japan
Contact:

Post by sheamkennedy »

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.
⊕ P E R S O N A L M U S I C: https://open.spotify.com/album/6fEo3fCm5C3XhtFRflfANr
� C O L L A B M U S I C: https://dustpuppets.bandcamp.com/releases
User avatar
Gizmog
Metal King Slime
Posts: 2615
Joined: Tue Feb 19, 2008 5:41 am

Post by Gizmog »

TMC
Metal King Slime
Posts: 4101
Joined: Sun Apr 10, 2011 9:19 am

Post by TMC »

The correct solution would be to write

Code: Select all

current display tile (read map block(x, y, 0), 0) == 23
It sounds like you wrote

Code: Select all

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:

Code: Select all

read map block((hero pixel x + 10)/20, (hero pixel y + 10)/20, 0)
Last edited by TMC on Tue May 19, 2015 9:05 pm, edited 1 time in total.
User avatar
sheamkennedy
Liquid Metal Slime
Posts: 1110
Joined: Mon Sep 16, 2013 9:29 pm
Location: Tama-shi, Tokyo, Japan
Contact:

Post by sheamkennedy »

Nice! You answered my next set of questions before I even asked. Your way has been implemented and works great.
Last edited by sheamkennedy on Wed May 20, 2015 3:40 am, edited 1 time in total.
⊕ P E R S O N A L M U S I C: https://open.spotify.com/album/6fEo3fCm5C3XhtFRflfANr
� C O L L A B M U S I C: https://dustpuppets.bandcamp.com/releases
TMC
Metal King Slime
Posts: 4101
Joined: Sun Apr 10, 2011 9:19 am

Post by TMC »

Haha, great.
Post Reply