How can I test for a on button press event?

Status
Not open for further replies.

IsFutureBright

Lightning Bolt Action
Veteran
Joined
Dec 26, 2012
Messages
120
Reaction score
11
First Language
Portuguese
Primarily Uses
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...
 

Tsukihime

Veteran
Veteran
Joined
Jun 30, 2012
Messages
8,564
Reaction score
3,846
First Language
English
Code:
Input.trigger?(:C)
Checks whether the game key C was hit.
 
Last edited by a moderator:

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,098
Reaction score
13,704
First Language
English
Primarily Uses
RMMV
:C is the enter or space key - the one that triggers an event set to 'Action Button'
 

IsFutureBright

Lightning Bolt Action
Veteran
Joined
Dec 26, 2012
Messages
120
Reaction score
11
First Language
Portuguese
Primarily Uses
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 
 
Last edited by a moderator:

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,098
Reaction score
13,704
First Language
English
Primarily Uses
RMMV
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)
 

IsFutureBright

Lightning Bolt Action
Veteran
Joined
Dec 26, 2012
Messages
120
Reaction score
11
First Language
Portuguese
Primarily Uses
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?
 
Last edited by a moderator:

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,098
Reaction score
13,704
First Language
English
Primarily Uses
RMMV
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).
 

IsFutureBright

Lightning Bolt Action
Veteran
Joined
Dec 26, 2012
Messages
120
Reaction score
11
First Language
Portuguese
Primarily Uses
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
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,098
Reaction score
13,704
First Language
English
Primarily Uses
RMMV
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.
 

IsFutureBright

Lightning Bolt Action
Veteran
Joined
Dec 26, 2012
Messages
120
Reaction score
11
First Language
Portuguese
Primarily Uses
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?
 
Last edited by a moderator:

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,098
Reaction score
13,704
First Language
English
Primarily Uses
RMMV
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.
 
Status
Not open for further replies.

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

Latest Threads

Latest Posts

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,078
Members
137,580
Latest member
Snavi
Top