How can I test for a on button press event?

I want to test if a button was just clicked, not being hold, but just got clicked on. Is there any quick script for that? I need it in a if condition not on the event's page...
Code:
Input.trigger?(:C)
Checks whether the game key C was hit.
:C is the enter or space key - the one that triggers an event set to 'Action Button'
I see. While I have your guys attention, is there any quick way to test X,Y distance to the player? I saw a distance_x.. something function but It wasn't found when calling from an event's page though. I wish it was easier to program on VXAce (like a nice IDE).

I'm currently doing something like:

(@game_map.events[@event_id].x - @game_player.x).abs 

(@game_map.events[@event_id].y - @game_player.y).abs 
The distance between a player and an x, y coordinate (in # of tiles) is


Math.hypot($game_player.x - x, $game_player.y - y)


If you use this in a method within Game_Player, then you just need @x and @y instead of $game_player.x and $game_player.y


if x and y (where you're calculating the distance to) are the coordinates of an event, then you'd use $game_map.events[id].x and $game_map.events[id].y where id is the event number (no leading zeros)
The distance between a player and an x, y coordinate (in # of tiles) is

Math.hypot($game_player.x - x, $game_player.y - y)

If you use this in a method within Game_Player, then you just need @x and @y instead of $game_player.x and $game_player.y

if x and y (where you're calculating the distance to) are the coordinates of an event, then you'd use $game_map.events[id].x and $game_map.events[id].y where id is the event number (no leading zeros)
The thing is I re use the same event commands for my other events that's why I'm using @event_id (that get's the id of the event this event command is being called on, right?). I saw this function on the Event class

 #--------------------------------------------------------------------------

  # * Determine if Near Player

  #--------------------------------------------------------------------------

  def near_the_player?

    sx = distance_x_from($game_player.x).abs

    sy = distance_y_from($game_player.y).abs

    sx + sy < 20

  end

 

Isn't there any way that I call this distance_x_from($game_player.x).abs from the event page and get the result distance?
You could use $game_map.events[@event_id].near_the_player? in a Call Script command if you wanted to use the same value (dist-x + dist-y < 20).
Yeah I don't want the same value but I think I could write a new function like this one to help me out....

 def near_the_player?(disX, disY)

    sx = distance_x_from($game_player.x).abs

    sy = distance_y_from($game_player.y).abs

    (sx <= disX && sy <= disY)

  end
yeah, that'd work.


Just realize you're going to have to break the command over two lines for this (at least), and breaking in the wrong spot could cause it to crash even though there's technically nothing wrong with it. If you break, do it after a [ or = or before a ] so it knows there's more to come.
I managed to get $game_map.events[@event_id].near_the_player?(0, 1) to work. What did you mean by breaking the command into two lines?
If it works, you don't need to worry about it. If you use the same format and it crashes, that'll probably be the reason.

If you do something like this in a Call Script event command, the game will crash:

$game_map.events[@event_id].near_the_player?(0, 1)You have to change where the line break happens:
Code:
$game_map.events[@event_id].near_the_player?(0, 1)
Anyways, it sounds like you've got it working now, and this has deviated from the thread subject, so 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.

Original thread: https://forums.rpgmakerweb.com/threads/how-can-i-test-for-a-on-button-press-event.17266/