Need help with For-Next Loop to check player/event collision in range of events

I understand the logic behind RGSS but I'm not up to snuff on the proper syntax, callwords, etc.

Here's what I'm trying to do.

I've got a line of events like spikes or lava or whatever behind the player that continually move up in a straight line together forcing the player to keep running forward or else he takes damage.  The event id's are 3 - 17.

I could use events to check for collision between the player's mapx,y and each event's x,y but I would need to create a x,y variable for all 15 events. 

So I'm trying to use a script or a conditional branch-script to check for player collision between the player's position and any of the events' x,y.

I don't know how I could squeeze this into a conditional branch, it would need some sort of line break I think but I'm not sure.

Here's what I tried to use as a script in a parallel process event to check for player/event collision.

common event 4 makes the screen flash, plays a damage sound, reduces HP and bumps the player forward

eventrange = [3..17]for val in eventrangeif $game_player.x == $game_map.events[eventrange].xand $game_player.y == $game_map.events[eventrange].ythen $game_temp.reserve_common_event(4)endendI'm pretty sure that I've got the idea...but that my syntax is all jacked up.

Edit: Woops, forgot to put had [eventrange]x instead of [eventrange].x but still getting an error.

Now it says, unexpected keyword_and

I keep trying to reword or adjust the line breaks and I just keep getting different errors.

So to replicate this, create 2 events (they don't have to move) and a player.

I want to check if the player's x,y = the event's x,y of each event, then do something if it does.

So instead of if player's x, y = event1's x,y then do something; if player's x,y = event2's x,y then do something and so on...

I want if player's x,y =event(1...2)'s x,y then do something or alternatively an array with specified event id's like event(1, 3, 5, 6, 10, 13) whatever.
Well, I managed to figure it out on my own.

(3..17).each do |i| px=$game_player.x py=$game_player.y ex=$game_map.events.x ey=$game_map.events.y  if px == ex and py == ey  then $game_temp.reserve_common_event(4) endendThanks me.

I guess the problem was I was trying to use [3..17] when it should have been (3..17)?

*Note: I used local variables in the script because the script parser for events seems

to be sorta picky about long script lines.
Actually, your array is fine, but you're using array instead of the event number, and that would cause problem.

if $game_player.x == $game_map.events[eventrange].xis equivalent to:

if $game_player.x == $game_map.events[[3..17]].xSo it should be changed to:

if $game_player.x == $game_map.events[val].xOne way to manual debug your code is by checking every key variable in it, and confirm that they display the desired value.

This is a traditional / lazy way to do it:

print("\nyour_variable_here = #{your_variable_here}") #Put Marker To Erase Later printed string will be displayed in the console window.
Actually, your array is fine, but you're using array instead of the event number, and that would cause problem.

if $game_player.x == $game_map.events[eventrange].xis equivalent to:

if $game_player.x == $game_map.events[[3..17]].xSo it should be changed to:

if $game_player.x == $game_map.events[val].xOne way to manual debug your code is by checking every key variable in it, and confirm that they display the desired value.

This is a traditional / lazy way to do it:

print("\nyour_variable_here = #{your_variable_here}") #Put Marker To Erase Later printed string will be displayed in the console window.
Ah, I see.  Thanks for the clarification.  I'm not 100% how I would just make an actual game function for this versus calling the script from an event but that would probably be even better I imagine.  I'll figure it out though.

Original thread: https://forums.rpgmakerweb.com/threads/need-help-with-for-next-loop-to-check-player-event-collision-in-range-of-events.25153/