Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

Obtaining Event ID based on x and y coordinates?

Is it possible to set two variables, one for x and one for y, and then find the event id of the event at the location specified by the x and y coordinates? There was a feature like this in rm2k3, but it seems to have been lost in XP.

Thanks :D!
 

Atoa

Member

you could try this:

if [$game_map.events[ID].x, $game_map.events[ID].y] == [Value X, Value Y]

Ex.:
i want to check if event ID 12 in on coordinate 25 x 13

if [$game_map.events[10].x, $game_map.events[10].y] == [25, 13]

(if you use the command "script" on an event conditional branch, don't add the "if" on the begin)
 
only by script, I believe.
[rgss]class Interpreter
  def event_at(x,y)
    for key in $game_map.events.keys
      event = $game_map.events[key]
      if (event.x==x and event.y==y)
        return event.id
      end
    end
    # if no event is at x,y
    return nil
  end
end
[/rgss]
^ should work in theory. do: $game_variables = event_at(x,y)
to save the event ID in variable number #i

Edit: shoot Atoa beat me to it :p
 
Atoa":5qqf6hux said:
you could try this:

if [$game_map.events[ID].x, $game_map.events[ID].y] == [Value X, Value Y]

Ex.:
i want to check if event ID 12 in on coordinate 25 x 13

if [$game_map.events[10].x, $game_map.events[10].y] == [25, 13]

(if you use the command "script" on an event conditional branch, don't add the "if" on the begin)
This works, but I need to be able to do this in reverse. I need to be able to define the coordinates and determine which event is at those coordinates.

silver wind":5qqf6hux said:
only by script, I believe.
[rgss]class Interpreter
  def event_at(x,y)
    for key in $game_map.events.keys
      event = $game_map.events[key]
      if (event.x==x and event.y==y)
        return event.id
      end
    end
    # if no event is at x,y
    return nil
  end
end
[/rgss]
^ should work in theory. do: $game_variables = event_at(x,y)
to save the event ID in variable number #i

Edit: shoot Atoa beat me to it :p

This is exactly what I'm looking for, but is there any way for me to be able to set x and y to two game variables? I've tried a few things, but I don't seem to have enough space within the script box in an event to define x and y as game variables. Of course, I'm not even sure if it would work. This is what I tried:
Code:
$game_variables[3] = event_at($game_variables[1],$game_variables[2])

But the script box breaks it up into:

Code:
$game_variables[3] = event_at

($game_variables[1],

$game_variables[2])

So I get syntax errors. Thanks for all of the help so far. Sorry that I don't know what I'm doing. I'm learning albeit slowly.
 
Ah, okay! It works perfectly, and it isn't complex at all.

Thank you very much, both of you!

EDIT: I'm having a somewhat unrelated issue, but it's also somewhat related, so I figured I'd just ask here instead of starting a new thread. It's based upon that exact same issue that I was just having; the script box is too small!

Anyway, I'm attempting to determine the event id of event1, whose coordinates are set to variables 38(x) and 39(y), after which I want to turn event1's A switch on. This is what I have:

Code:
x=$game_variables[38]

y=$game_variables[39]

$game_variables[37] = event_at(x,y)
And then, in a separate script box:
Code:
key = [$game_variables[27], $game_variables[37], 'A']

  $game_self_switches[key] = true

  $game_map.need_refresh = true
Note: Variable 27 stores the current map id.

However, the second script box is actually displayed like this, because it's so small:
Code:
key = [$game_variables[27],

$game_variables[37], 'A']

  $game_self_switches[key] = true

  $game_map.need_refresh = true

Seeing as how it doesn't work, I'm assuming that the tiny script box has broken my script again. Does anyone know of a work-around that I could use?

EDIT2: Got it! There was a conflicting event that I made days ago on the same map :|

Thanks, everyone :3

EDIT3: Just thought that I'd let you know that I found a wonderful use for your suggestion too, Atoa :3
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top