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

DorkLord

10th Level Google Mage
Veteran
Joined
Aug 1, 2013
Messages
47
Reaction score
26
First Language
English
Primarily Uses
N/A
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.
 
Last edited by a moderator:

DorkLord

10th Level Google Mage
Veteran
Joined
Aug 1, 2013
Messages
47
Reaction score
26
First Language
English
Primarily Uses
N/A
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.
 
Last edited by a moderator:

Mike

Veteran
Veteran
Joined
Aug 28, 2013
Messages
316
Reaction score
36
First Language
English
Primarily Uses
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.
 

DorkLord

10th Level Google Mage
Veteran
Joined
Aug 1, 2013
Messages
47
Reaction score
26
First Language
English
Primarily Uses
N/A
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.
 
Last edited by a moderator:

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Profile Posts

so hopefully tomorrow i get to go home from the hospital i've been here for 5 days already and it's driving me mad. I miss my family like crazy but at least I get to use my own toiletries and my own clothes. My mom is coming to visit soon i can't wait to see her cause i miss her the most. :kaojoy:
Couple hours of work. Might use in my game as a secret find or something. Not sure. Fancy though no? :D
Holy stink, where have I been? Well, I started my temporary job this week. So less time to spend on game design... :(
Cartoonier cloud cover that better fits the art style, as well as (slightly) improved blending/fading... fading clouds when there are larger patterns is still somewhat abrupt for some reason.
Do you Find Tilesetting or Looking for Tilesets/Plugins more fun? Personally I like making my tileset for my Game (Cretaceous Park TM) xD

Forum statistics

Threads
105,868
Messages
1,017,074
Members
137,578
Latest member
JamesLightning
Top