Spike Trap Help

Hello! I'm trying to make spikes that cycle between a on spike and off spike. Off spikes are nonsolid items that are safe to walk through, but On spikes will lower your health upon stepping on them. They should switch every one second. I was able to do this fine, and they work well, except for one problem. They only work if you walk onto them. for example, if you stand on an off spike and wait one second, and it becomes an on spike, although you are on it, you don't take damage. I've tried changing the on spike to an item instead of a sprite, but that didn't work either. What should I do?
ezgif-2-1277754560

I've come across this too, every time it switches, do this:

tell event.player to
call "spike_check"

and "spike_check" would be an event for the player that would do this:


tell event.px,event.py to call "interact"

That way, when the spike switches, it will interact with whatever they are standing on.

1 Like

Thank you, this helped a lot! I'm sorry but can you please help with one more problem with the spikes? Because I have the spikes switch off every one second, after you leave a room with spikes, some weird stuff can happen. See below for example.
ezgif-6-7a32516f25
It appears in the same place in every room. How would I be able to get them to stop appearing in other rooms? Thank you!

Room specific spikes are all I can think of right now, a spike that checks what room the game is in, and compares that to it’s own name (which would be the same as the room’s name).

spike_name = name event.x,event.y
if event.room==spike_name then
//this would be your actual switching code

This isn’t the cleanest solution, but I tested it and it works.

1 Like

Thank you so much for all of your help!

Hey, so I know this has already been solved, but I was running into this same problem and I just wanted to share the solution I found. Rather than actually swapping the tile each time, you can use "frame" and just switch the frames each time, and only take health if it is on one of the frames, like this:

wait 1 then
if frameIndex==0 then
frameIndex=1
frame frameIndex
takeHealth=1
end
if frameIndex==1 then
frameIndex=0
frame frameIndex
takeHealth=0
end

Then, using the "takeHealth" variable, you could tell the item whether or not you want to take health. As I have found, this works fairly well and is simpler, plus it solves the problem of the tile showing up in other rooms.