Jump to content
New account registrations are disabed. This website is now an archive. Read more here.
  • 0
HeathLocke

Get properties from specific map using id

Question

Hello.

I'm trying to get the width and height of a map using its id, while the player is in another map, with a different ID.

I've been able to do this with this code:

currentMapId = $game_map.map_id # Stores current map id to use later
$game_map.setup(mapId) # Changes map id to get properties
mapWidth = $game_map.width # Getting the properties
mapHeight = $game_map.height
$game_map.setup(currentMapId) # Reverting the map id to its original state (so that the player does not teleports)

But I feel this is a really dirty trick. Isn't there a simpler way to do this? Something like $game_map[mapId].width/height.

 

Edit: I would preferably not edit Game_Map or anything like that. If it is really necessary, how can I make the change in a new script page, instead of just editing the default file?

Edited by HeathLocke

Share this post


Link to post
Share on other sites

2 answers to this question

Recommended Posts

  • 0

Well, this is rather easy :v

$MAP = Game_Map.new
$MAP.setup(mapId)
mapWidth = $MAP.width
mapHeight = $MAP.height

And done. You can rename MAP to anything you'd like :)

 

EDIT :

Turns out that I've found an easier way :v

$MAP = load_data("Data/MapXXX.rxdata")
mapWidth = $MAP.width
mapHeight = $MAP.height

Change XXX with your map id.

Remember that each X must represent a number, so if your map id is 1, change XXX into 001.

 

EDIT 2 :

My bad, I've found an easier way than before.

mapWidth = load_data("Data/MapXXX.rxdata").width
mapHeight = load_data("Data/MapXXX.rxdata").height

I think it won't got easier than this.

Edited by black mage

Share this post


Link to post
Share on other sites
  • 0

Hey, thanks a lot!

Also for anybody finding this thread from google or something, since my mapId changes, here is the code to make it match with RMXP's naming format:

mapIdNum = mapId.to_s.rjust(3, "0") # .to_s is only necessary if your map id is a number
mapWidth = load_data("Data/Map#{mapIdNum}.rxdata").width 
mapHeight = load_data("Data/Map#{mapIdNum}.rxdata").height 
Edited by HeathLocke

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...