How do I Access Map Data in order to Automate Transfer Coordinates?

Here's what I want to do:

1) When the player reaches the edge of a map, they will transfer to a randomly selected map. (I've sorted that out, it's a series of conditionals based on a random number call)

2) When the player arrives at the new map, their position will be automatically chosen based on their previous X and Y coordinates.  

  • For example, The player is the top of the screen with coordinates X=25 and Y=0 on Map 001,
  • The Event is triggered, Player X & Y data is stored as a variable and the player is transferred to one of the random maps, the map could be any width or height (with a minimum of 26 in either X or Y)
  • The new X coordinate for the player would remain 25 (taken from the stored variable), and the new Y coordinate would be (Map Y Height -1) placing the player at the bottom part of the map one tile away from the edge (so that they don't trigger another transfer event).

I have part of this is already set up - I store the player X & Y game data as variables when the player leaves the map.  But I don't know how to collect the data on the dimensions of Map 005.

3) How do I collect data about a map the player isn't in yet?

4) And if I have to wait for the player to arrive in the map first, how do I access the information about the Map's current maximum width and height?

Any help would be appreciated.  Thanks very much.
$game_map.width

$game_map.height

I'm not sure if it returns pixels or the grid-based values though

or if you want to do something before going to the map, something like this can be done

Code:
x=load_data(sprintf("Data/Map%03d.rvdata2", map_id))x.widthx.height
Thank you so much!

So let me try and say it back to you to make sure I understand properly:

1) I would set up two variables (let's call them MAP X and MAP Y) that load the map data of the map I'm about to enter via a script call using the control variables.

2) I Set MAP X to ($game_map.width - 1) and Set MAP Y to ($game_map.height - 1)

(The reason I subtract 1 is because the player can't be placed on an edge tile.)

3) Then do a "Transfer Designation With Variables" using the variables I just created and the Random Map ID that I just called.

The only part I don't understand is where to include this script and in what part of the event.

Code:
x=load_data(sprintf("Data/Map%03d.rvdata2", map_id)) # is the X a variable that I can designate, and how do I select width vs. height?x.widthx.height
yes, x on the script code I posted means any variable


Btw, those are two different methods... the one that uses $game_map is only usable for the current map you're on... the second one (the one with the script) is the one that you will use if you need to load data of another map
Ah!

So if I want to load Width from a different map into a variable then I would do:

Control Variable

Set MAP X to 

Script

load_data(sprintf("Data/Map%03d.rvdata2", map_id)) x.width

and 

Control Variable

Set MAP Y to 

Script

load_data(sprintf("Data/Map%03d.rvdata2", map_id)) x.height

---

So here's a related question - can "map_id" be set by the random number variable that gets called at the beginning of the event?

The formula would then look like:

Control Variable

Set MAP X to 

Script

load_data(sprintf("Data/Map%03d.rvdata2", Random_Number)) x.width

and 

Control Variable

Set MAP Y to 

Script

load_data(sprintf("Data/Map%03d.rvdata2", Random_Number)) x.height
that should be like


Set MAP X to


load_data(sprintf("Data/Map%03d.rvdata2", $game_variables[id_of_random_number_variable])).width
Engr. Adiktuzmiko, Thank you very much for your help and walking me through this step by step.  It's always a great feeling when the logic and the code finally synchronize 🙂

load_data(sprintf("Data/Map%03d.rvdata2", $game_variables[id_of_random_number_variable])).width -1

can I manipulate the data by simply adding -1 to the end of the script or do I need to write it out differently?
adding a -1 at the end will be fine
Using #width and #height on a map object will give you the number of tiles for width and height respectively. If you wish to get the coordinates for the current map, pick a point that is less than $game_map.width for the x coordinate, and less than $game_map.height for the y coordinate.

In order to get coordinates for a different map, you'll need to load the map first. One such way is to do

map = load_data(sprintf("Data/Map%03d", choose_a_map_id))# The map's width in tilesmap.width# the map's height in tilesmap.heightIn order to assign the coordinates to a variable via scripting you would do

$game_variables[choose_a_number_for_x] = x_position$game_variables[choose_a_number_for_y] = y_positionOr if you're feeling advanced and want to use arrays:

Code:
$game_variables[choose_a_number_for_position] = [x_position, y_position]
So here's what I plug into the script:

game variable 22 - is a random number

game variable 23 - is the Map's Maximum width - 1

game variable 24 - is the Map's Maximum height -1

map = load_data(sprintf("Data/Map%03d", $game_variables[22]))# The map's width in tilesmap.width# the map's height in tilesmap.height$game_variables[23] = map.width -1$game_variables[24] = map.height -1But then it tells me it's unable to load Map data.  What have I done wrong?

edit: I also tried adding .rvdata2 to it just in case but that gave me an argument error.
maybe, the variable returns a wrong map id
Well here's the thing, I'm using test maps so I know the maps exist. For example MAP012 has ID 012.

When I put the number 12 into the script it says it can't find the data for that map.  It doesn't make much sense to me.

edit: argh it just doesn't seem to work.  It keeps telling me "unable to find file MAP012"
can you post the actual error? like a screenshot or so
Do a

Code:
p $game_variables[22]
in your script before the map load, just to see what it's trying to load.
Attached is the common event I'm creating. it's partially finished, and set up to only load MAP 12 then tell me the coordinates of the map.

There's something wrong.

Scripting Issue.png
can you post the actual error? like a screenshot of it?


anyway, recheck your folders to see if the file really exist there...


you can also try to manually go to map 12 and see if it errors since the map setup method also uses that same loading mechanism
load_data(sprintf('Data/Map%03d.rvdata2', $game_variables[22]))
Okay, I tried that and I'm getting new errors now.  But I'm starting to see where I've been going wrong.  I thought that the 'Data/Map%012.rvdata2' part of the script was simply the first part of the address and that the random number variable was being added to the end.  In my Data folder, map 12 is labeled Map012 and that's what I labeled it in-game while testing the map.

In any case, the new error is: malformed format string - %r

I don't know what that means.

I then removed the rvdata2 and got a second error - this time it was a %*(0-9) error.

so I guess I'm not as sure about the process of loading the information as I had originally thought.
It should still be %03d, at least that's how Game_Map handles it:

take a look:

Code:
@map = load_data(sprintf("Data/Map%03d.rvdata2", @map_id))
AFAIK, %03d denotes where the additional string will be placed...
So when you write @map_id you would just put a number or would you write @number?

Also, I'm closer to getting it working now.  It's not crashing anymore, but when I try and get the text to load in order to show me the variables, the text bar doesn't open - it tries to, then just becomes a line.

Very weird. Is it the nature of the trigger or the nature of the how the event progresses? I'm basically making a player touch event that calls the common event.

Original thread: https://forums.rpgmakerweb.com/threads/how-do-i-access-map-data-in-order-to-automate-transfer-coordinates.25647/