Figuring out the distance from the player?

Status
Not open for further replies.

Stupidbro

Veteran
Veteran
Joined
Jul 8, 2019
Messages
87
Reaction score
8
First Language
English
Primarily Uses
RMVXA
So, my end goal is to be able to create proximity sounds, but I've run into an issue I wasn't expecting. I'm not experienced with Ruby scripts, but I'd seen a specific couple of lines that I thought should work:
Ruby:
sx = distance_x_from($game_player.x).abs
sy = distance_y_from($game_player.y).abs
But when the event is triggered, it gives the error message:
"Script 'Game_Interpreter' line 1411: NoMethodError occured.

undefined method 'distance_x_from' for #<Game_Interpreter:0xd4c39f4>"

So, anybody able to help me figure out what's wrong?
 

estriole

Veteran
Veteran
Joined
Jun 27, 2012
Messages
1,283
Reaction score
512
First Language
indonesian
So, my end goal is to be able to create proximity sounds, but I've run into an issue I wasn't expecting. I'm not experienced with Ruby scripts, but I'd seen a specific couple of lines that I thought should work:
Ruby:
sx = distance_x_from($game_player.x).abs
sy = distance_y_from($game_player.y).abs
But when the event is triggered, it gives the error message:
"Script 'Game_Interpreter' line 1411: NoMethodError occured.

undefined method 'distance_x_from' for #<Game_Interpreter:0xd4c39f4>"

So, anybody able to help me figure out what's wrong?
that means there's no method called distance_x_from or distance_y_from defined in the Game_Interpreter... the line you see working might be from other script that define that method inside Game_Interpreter. you might want to have that script installed if you want it to work...

if you're did not want to have that script... i think you can also get the event x and y that currently executing the event command with:
Code:
ex = $game_map.events[@event_id].x
ey = $game_map.events[@event_id].y
for player you can use:
Code:
px = $game_player.x
py = $game_player.y
but... if i remember correctly we can also store above in variables...
there's a built in function that can grab that gamedata and store it in control variable event command.
you can store them in the variables... and then you can calculate it to know the 'distance'...

i cannot test above because currently my ACE is already uninstalled... but hope this help.

edit: i think the script you see is this:

but using that script... your way of calling the method still wrong though... you need to pass the eventid and the player pos...
so maybe this:
Code:
sx = distance_x_from(@event_id,$game_player.x).abs
sy = distance_y_from(@event_id,$game_player.y).abs
hope this help.
 
Last edited:

Stupidbro

Veteran
Veteran
Joined
Jul 8, 2019
Messages
87
Reaction score
8
First Language
English
Primarily Uses
RMVXA
Okay, so I get this:
that means there's no method called distance_x_from or distance_y_from defined in the Game_Interpreter...
but I'm not sure what you mean by
the line you see working might be from other script that define that method inside Game_Interpreter. you might want to have that script installed if you want it to work...
Are you saying that the script is defined by a different base script or are you saying that an added script is interfering? Because I have modified a few scripts, but I haven't added any.
Edit:
Can these be consolidated
Code:
ex = $game_map.events[@event_id].x
ey = $game_map.events[@event_id].y
Code:
px = $game_player.x
py = $game_player.y
into
Code:
dx = $game_map.events[@event_id].x - $game_player.x
dy = $game_map.events[@event_id].y - $game_player.y
edit: i think the script you see is this:
I actually took it directly from the core script Game_Events, lines 140-141, not sure if that will help at all, but it can't hurt.
but using that script... your way of calling the method still wrong though... you need to pass the eventid and the player pos...
so maybe this:
Code:
sx = distance_x_from(@event_id,$game_player.x).abs
sy = distance_y_from(@event_id,$game_player.y).abs
I just tried using that and got the exact same error message. I'm going to try the first method and get back to you.
Edit:
First method definitively works.
 

estriole

Veteran
Veteran
Joined
Jun 27, 2012
Messages
1,283
Reaction score
512
First Language
indonesian
Okay, so I get this: but I'm not sure what you mean by Are you saying that the script is defined by a different base script or are you saying that an added script is interfering? Because I have modified a few scripts, but I haven't added any.
Edit:
Can these be consolidated
Code:
ex = $game_map.events[@event_id].x
ey = $game_map.events[@event_id].y
Code:
px = $game_player.x
py = $game_player.y
into
Code:
dx = $game_map.events[@event_id].x - $game_player.x
dy = $game_map.events[@event_id].y - $game_player.y
I actually took it directly from the core script Game_Events, lines 140-141, not sure if that will help at all, but it can't hurt.

I just tried using that and got the exact same error message. I'm going to try the first method and get back to you.
Edit:
First method definitively works.
ah... it's on Game_Events... that's why it doesn't work...

if you script call something using event command... it's inside Game_Interpreter environment... so you cannot call the method from Game_Events without referencing to the events...
ex:
Code:
sx = distance_x_from($game_player.x).abs
will throw error because Game_Interpreter did not have method called distance_x_from
but
Code:
sx = $game_map.events[@event_id].distance_x_from($game_player.x).abs
will work... because $game_map.events[@event_id] is a Game_Events... and we're calling it's distance_x_from method.

Code:
dx = $game_map.events[@event_id].x - $game_player.x
dy = $game_map.events[@event_id].y - $game_player.y
i think this should works in theory... hope this help.
 
Last edited:

mlogan

Global Moderators
Global Mod
Joined
Mar 18, 2012
Messages
15,329
Reaction score
8,522
First Language
English
Primarily Uses
RMMV

This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

 
Status
Not open for further replies.

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

Latest Threads

Latest Posts

Latest Profile Posts

being able to transition music seamlessly is amazing. my main character's theme has lyrics and it goes from vocal version to istrumental when he leaves his room. and vice versa. and thanks to a plugin, the transition is seamless. I love it.
All of the auditions for our game are so good, I'm so glad I'm not in charge of choosing completely. lol I just can't with some of them. I listen to them on repeat. XD
Working on a Patch to integrate AlphaABS into random generated Dungeons. Was a bit tricky, but the outcome is a real Life Changer!!

Will release it the next days!
Been pretty busy... but I got a better headset for recording and listening today. Dad says that he'll consider taking me to Great Wolf Lodge for the first time once I finish summer classes (my final semester!) I'll be taking my plushie friends with me: Bendy, Lolbit, and Helen Henny. (I WUV PLUSHIES!)
SF_Monster3,4 added!

Forum statistics

Threads
105,651
Messages
1,015,301
Members
137,327
Latest member
Mezzy
Top