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

replace the @map_id with $game_variables[22], or just edit the code ur already using so that it uses %03d instead of %012


Are you by any chance using Yanfly's message script? because if yes, then variable 22 might also be the variable used by the script to denote the height of the text window...
Okay I've solved all the issues so far.

Attached are two separate events that when triggered will randomly transition between maps while also preserving coordinate accuracy.

  • The first attachment, marked Random Map Travel is common event script that can be called from any local event on a map.  It determines

a) A random number

😎 Makes that random number equivalent to a map id. (for example, random number 12 is also map 12)

c) Then calls in the Coordinate Transfer System (a separate common event)

d) Then ends the event so it doesn't jump the player all over the place.

  • The second attachment, marked Script Solution is another common event that determines, on an automatic level, where to position the player when they move to a new map.  This way, I the game designer, don't have to constantly create designated arrival areas.  The event is pretty intense, so let me give the run down and an explanation of a few key things.

a) The event loads information about the map the player is about to enter.

😎 It takes the height and width information and dumps it into two variables so I can manipulate the information later.

c) I deduct 2 from each of the height and width variables. Why? Because, although a map may be 20x20, the useable area will only be 19x19 and I also want a 1 square space between the player and any borders (again so they don't end up teleporting all over the place)

d) Now the event loads all the information about the current map. The map's dimensions and the player's coordinates are dumped into their own variables.

e) Again, I deduct 2 from the map's dimensions.  This is in order to enable proper re-positioning when a player moves from either the far X (right) or far Y (down) on map 1 and wants to arrive in the correct spot on map 2.

f) Here are the conditions by which the new coordinates will be picked.  They are all dependant on the player's current X and Y coordinates, and the Height and Width of the map they are about to arrive in.

g) I added the Jump To label function because once the coordinates have been picked, I don't want the event to run through them again and alter them twice. I'm not actually sure if I need that in there, but it's a remnant from lots of testing and it does no harm so I left it in.

h) The event jumps to the Transfer label

I) The player is transferred using the variables established by the random number generated (representing the Map ID), the new map X coordinates, and the new map y coordinates.

J) Now, when a player exits a map from the left they will appear on the new map on the right hand side.  If they leave from the top part of the map they arrive in the bottom part of the next map.  And it's all automated now.

That should cover my bases for now.  The next step is creating a system so that the game remembers the order in which the random maps appeared, so that if I were to go back the way I came, I would encounter the maps in the right order.  That's a task for a different day. It's 320am where I am right now and I am so pooped.

Thanks to everyone for your help. It means a lot. And for anyone else with similar problems, I'm more than happy to troubleshoot.

Random Map Travel.png

Script Solution.png
For that, I would use a variable, and make it into an array. Each time you go to a new map, put the current map into the array. Each time you return from the new map, grab the last element of the array. OR if you want to keep it, so going through the same exit again will take you to the same map again (so it's random the first time you go there, but each time after that it stays the same), use a second variable to keep track of your "sequence" number and use that to grab the map id.


How are you keeping track of which maps they've been to, so they're not chosen by the random number generator? I suspect even what you have (besides the next comment) will need to be adjusted.


Notes on your screenshots ... you don't need all those conditional branches in the first common event. They're all exactly the same. Just set the random number, then call the other common event.
Thanks Shaz,

I took a look at removing the conditions and of course it works, but what if in the future I add 20 new maps, but only 10 are for random travel and they aren't in order?  The random number generator has to extend to incorporate all of the new maps, but then I need to make sure that if the random number generator encounters a map ID that should not be used it will re-roll the number until it gets one it can use.  Setting up conditions allows me to make sure that everything works out without the script fizzling out or loading a boss map by accident.

---

Okay, arrays have never been my thing. I get that it's very similar to creating an imaginary spreadsheet that is fully flexible and expandable, and then you just add/take/read the information when you need to.  For some reason, half way through the process of creation, while juggling the logic and the systems design, I drop a piece and can't find the issue.

I've attached a new image of what I'm hoping to achieve though.  I can feel that the programming is just at the edge of my fingertips on this one.

I can see how parts of the conditionals would be set up. For example;

(not actual code)

Player reaches edge of map.Variables Global X and Global Y are altered depending on whether player exits left, right, up, down.Condition: Global X == 2 (this number is determined by which map they are currently in, for example at the start of the game, the player might be at (1,1)) Condition: Global Y == 3 (this number is determined the same way) Condition: Array information at position (Global X, Global Y) is blank Transfer player to random map. ELSE Transfer player to Map ID X (where X is the number that exists at Array (2, 3) Condition: Global Y == 4 Condition: Array information for (Global X, Global Y) is blank Transfer player to random map. ELSE Transfer player to Map ID X (where X is the number that exists at Array (Global X, Global Y)There are problems with this though:

1) I have to write out a condition for EACH potential X and Y (annoying)

2) I have no idea to add or read information to an array (I can learn that)

X and Y map.png
Yeah, I've got an easier way, but it involves a little bit of scripting in a Control Variables command.


If I remember when I get home, I'll test it out a bit and post up the exact commands to use. If I don't post back in 24 hours, give me a reminder 🙂


Before I get into it though ...


Does each map only have two exits, so it's going to end up a pure linear path?


Should the player be able to keep going until ALL the specified maps have been added to the path?


Will you be adding or removing maps from the list of possible maps as the game progresses? What happens if you remove a map from the list and it's already been "discovered" by the player so is already in the path?
To answer your questions:

1) each map has 4 exits (and on each map there may be dozens of event points marking an exit) so the path may not end up a straight line. You can see that illustrated in the image I posted in my last post.

2) the player can keep going into infinity from a technical standpoint. Obviously I'll be making game play mechanics that prevent that, but the way the system works right now, a player can keep loading random map after random map. Just because I've already been to map 12 doesn't meant I won't encounter map 12 again later. And since the map ID is determined by a random number generator it's perfectly possible the player will go from map 12 to map 12.

3) the game will have Unique Maps at pre-determined Global X and Y coordinates. That means players can move through the world loading random maps with each change, but once they reach a specific global (X, Y) coordinate, the Unique Map will be loaded instead of a random one.

4) I don't have any plans to remove a map from the game (but of course it may come up) but let's say hypothetically I decided that I wanted to remove map 12 and the player has already been to map 12 at global (2, 3) and then later at global (5, 7). When the player reaches those coordinates again, the program will simply re-roll a random number and load a new map accordingly. Unfortunately I have no idea what syntax to use for that. Willing to teach myself if you point me in the right direction.

----

Since I last posted I did some research on arrays and I think I'm more comfortable with them.

I'll need to create a 2 dimensional array and then populate certain x and y positions with the Unique Maps.

Every other part of the array will start blank or with a null or whatever.

So when a player exits a map, the game

1.) calculates the player's (Global X, Global Y). (For example, if the player exits on the right, you would add 1 to Global X)

2.) It rolls a random number.

3.) It checks the array at (global x, global y) for a number.

3a.) If there IS a number there, it loads a map with the ID of that number. This will either be one of the Unique Maps, or a random map that has already been associated with this position in the array.

4) if the array returns a null or blank or "does not compute" (not sure on the terminology yet) then:

4a.) The script puts the random number into the array at global (x, y).

4b.) The player is transferred to a map with ID of the random number.

This ought to sort out my problems. I just don't know how to accurately express this logic in code. Principally, I'm not certain about the array syntax and the rationale for each bit of grammar. This is where I stumble.

ALSO

I've recently learned that when you check an array with a negative number (for example global (-3, 2)), it will draw information from the opposite end of the array, meaning it could accidentally load a Unique Map or previously connected Random Map. Have I understood that particular principle about arrays? The only workaround I can fathom is to create a separate array specifically to handle negative values of x or y.

Also, will the array have to run in a common event parallel process in order to preserve the contents of the array at all times? What's the proper procedure?

So it's become complex, I know, but it's quite fun tow work this out. Often I'm not sure if it's my logic or my scripting that is the issue. I appreciate your help getting me this far. Please let me know if I need to be clearer.

---

I edited this post twice, both for clarity purposes but I also made some slight changes and wrote new questions.
If you make the array a game variable, it will always be preserved with the game. Just do a script call (or a Script in Control Variables) to set $game_variable[id] to [] to turn it into an array. That also means, then, that you'll end up with errors if you ever try and use it in an equation.
Okay so I have a new problem now.  The more I learn about Arrays, the better they seem as a solution to my problem, except there is a big catch: Ruby doesn't do multidimensional arrays.  So the alternative would be to do a jagged array, but I have no idea how to control those yet.  I'm taking a look into Tables now, so we'll see how that goes.  I'll post updates and solutions as I find them.
you can do arrays inside arrays though...


so like


X=[[0,1,2],[88,65,64]]


so x[0] returns [0,1,2]


to get the elements inside that you can do


x[0][0] => this will return 0


x[0][1] => returns 1


and so on...


It's basically just like doing multidimensional arrays, manually... or maybe you can do it like:


x=[[],[],[]]


then do something like


x[0][0] = value


x[0][1] = value


x[0][2] = value
I think we're on the same page, or at least very close.  Here's some code that I'm playing around with.  It's definitely not finished and some of the logic hasn't been implemented yet, but the setup is clearly there and you can see where it's going.

The issue is whether I've just been using too many variables and whether I understand variables well enough to get this right without accidentally moving the player to mars.

$game_variables[27] # The Random Number Generator, starting at 12 - # keep in mind that the number generator is being used to represent Map IDs, # Map 12 is the first map for this thought experiment.$game_variables[32] # The Global X Coordinate, begins at 0, not an array$game_variables[33] # The Global X Coordinate, begins at 0, not an array$game_variables[30] = [[$game_variables[32], $game_variables[33]]] # This array will contain coordinates that have already been explored, # the starting info will be [0, 0] at index 0, since the player is in the first map.$game_variables[31] = [[[$game_variables[30].at(-1)], $game_variables[27]]]] # This array combines the last element of the coordinate array (30) with # variable 27, (Random Number Generator) # the starting info will look like [[[0, 0], 12]] # So why have I made an array within an array within an array? # The answer is that when I want to do a search through this array and I'm looking for something # at index 13, I need the game to retrieve all three numbers, not just a single integer. So in # this instance; index 0 of the array = [[0, 0], 12]  # Likewise, index 0 of the inner array = [0, 0] (if I've understood arrays correctly) # And why have I separated variable 31 from 30? # Because I'm going to need to run checks against coordinates that may or may not have # been explored yet.# So, variable 31 is now an array containing smaller arrays of 3 pieces of information: [[Global X, Global Y], Map Number] # Right now we know the player is at global coordinates (0, 0) in Map 12.# Here's what we want to do next, in human terms;# When the player moves to a new map, either the Global X or the Global Y will change, those variables will be updated.  # For our experiment let's say, (1, 0).# # A Random number will be chosen and entered as the Map Number. # For our experiment let's say, 15.# # The game will run a comparison against array 30 to see if the (X, Y) combination exists (which would imply the area has been explored before.) # If the coordinates exist, the game will run a check against array 31 to find the sub-array containing sub-array with info "[1, 0]" # The map number will be at index 1 (remember arrays always start at 0, so 1 is the second number, also remember that the first array is in index 0) # Once it finds the coordinates, it will take whatever number is at index 1 of that sub-array. # If [1, 0] doesn't exist in array 30, then 1) array 30 is updated with a push of [1, 0] into the last index position, 2) array 31 is updated with # new info in a similar fashion and 3) the player is taken to the random map.

So, I'm making some progress, again most of the problem is that I'm learning syntax while also doing the logic, so if an error appears, it's harder to identify.
I Just wanted to insert that I am very close to solving this issue myself, and that when I do I will post it here, so please don't close this conversation yet.
[SIZE=10.5pt]Okay I solved the problem!   Using Nested Arrays and Events and no scripting!  [/SIZE]

[SIZE=10.5pt]Difficulty level:[/SIZE]

[SIZE=10.5pt]From 0 to knowledgeable in less than two weeks.[/SIZE]

[SIZE=10.5pt]So let's recap the task: [/SIZE]

[SIZE=10.5pt]How do we move from map to map, loading them randomly, but return to specific maps if the player turns back.[/SIZE]

[SIZE=18pt]Let's go through the process in player and program using human language, step by step:[/SIZE]

[SIZE=10.5pt]Player is exploring an unexplored area and adding each new location to a map.[/SIZE]

[SIZE=10.5pt]The program tracks various pieces of data that are all necessary ingredients. From a programming perspective, it's worth creating these variables in a separate one time event when the game begins:[/SIZE]

[SIZE=10.5pt]For player positioning:[/SIZE]

[SIZE=10pt]·         [/SIZE][SIZE=10.5pt]Player's Current Local X and Y coordinates. (that's two variables) [/SIZE][SIZE=10.5pt](In this thread we've already come to the solution about how load maps randomly, and how to automatically place the player in the new map at the correct position, read above for the answers.)[/SIZE]

[SIZE=10pt]·         [/SIZE][SIZE=10.5pt]Player's Previous Local X and Y coordinates. (Again that's two variables) [/SIZE][SIZE=10.5pt](In this thread we've already come to the solution about how load maps randomly, and how to automatically place the player in the new map at the correct position, read above for the answers.)[/SIZE]

[SIZE=10.5pt]For random maps and remembering them:[/SIZE]

[SIZE=10pt]·         [/SIZE][SIZE=10.5pt]Player's Future Global X and Y Coordinates (two variables) [/SIZE][SIZE=10.5pt](I'll explain later) (imagine the game maps are put together like a quilt - each map is sewn on based on what X and Y coordinate it has)[/SIZE]

[SIZE=10pt]·         [/SIZE][SIZE=10.5pt]Player's Current Global X and Y coordinates [/SIZE][SIZE=10.5pt](two variables) (somewhat redundant)[/SIZE]

[SIZE=10pt]·         [/SIZE][SIZE=10.5pt]Player's Future Map ID (to temporarily store a random number)[/SIZE]

[SIZE=10pt]·         [/SIZE][SIZE=10.5pt]Player's Current Map ID (somewhat redundant)[/SIZE]

[SIZE=10pt]·         [/SIZE][SIZE=10.5pt]A Random Number Generated to represent a Map ID[/SIZE]

[SIZE=10pt]·         [/SIZE][SIZE=10.5pt]The Width and Height of the Future Map (two variables)[/SIZE]

[SIZE=10pt]·         [/SIZE][SIZE=10.5pt]Array 1: An Array of Player's Future Global X and Y Coordinates (for example, [1, 0])[/SIZE]

[SIZE=10pt]·         [/SIZE][SIZE=10.5pt]Array 2: An Array of Player's Current Global X and Y coordinates (somewhat redundant but initially set at [0, 0]) [/SIZE]

[SIZE=10pt]·         [/SIZE][SIZE=10.5pt]Array 3:[/SIZE] [SIZE=10.5pt]An Array containing a list of all Array 1's that have been created.[/SIZE][SIZE=10.5pt] In other words: An array of all X and Y coordinates that have been visited. (The first one will be [[0, 0]])[/SIZE]

[SIZE=10pt]·         [/SIZE][SIZE=10.5pt]Array 4:[/SIZE] [SIZE=10.5pt]An Array containing Array 1 and the current Map ID.[/SIZE] [SIZE=10.5pt] An Array of an array of (yes I said that twice) Player's Current Global X and Y coordinates and Current Map ID. (For example, [[/SIZE][SIZE=10.5pt][[/SIZE][SIZE=10.5pt]0, 0[/SIZE][SIZE=10.5pt]][/SIZE][SIZE=10.5pt], Map ID][/SIZE]

[SIZE=10pt]·         [/SIZE][SIZE=10.5pt]Array 5: An Array containing a list of all Array 4's that have been created.  In other words: An array of the array all X and Y coordinates matched with the Map IDs that were randomly chosen when the player arrived. (For example, the initial value will look like [[[0, 0], Map ID]] that's an array nested within an array, within another array)[/SIZE]

[SIZE=10.5pt]This can be done in a common even and then summoned when the player triggers a local event:[/SIZE]

[SIZE=10.5pt]Step 1: The player reaches the edge of the map either on the local X or Y coordinate.[/SIZE]

[SIZE=10.5pt]Step 2: The program adds or subtracts 1 from one of the[/SIZE][SIZE=10.5pt] Future Global X and Y coordinates. [/SIZE][SIZE=10.5pt]For example, if Player is at Global (0, 0) and exits on the [/SIZE][SIZE=10.5pt]right[/SIZE] [SIZE=10.5pt]then the new coordinates would be (1, 0)[/SIZE]

Step 2: [SIZE=10.5pt]The program overwrites [/SIZE][SIZE=10.5pt]Array [/SIZE][SIZE=10.5pt]1 [/SIZE][SIZE=10.5pt]with [/SIZE][SIZE=10.5pt]Player's Future Global X and Y Coordinates.[/SIZE][SIZE=10.5pt] [/SIZE][SIZE=10.5pt] [/SIZE][SIZE=10.5pt](for example, [1, 0])[/SIZE]

[SIZE=10.5pt]Step 3: The program checks to see if Array 1 appears in[/SIZE] [SIZE=10.5pt]Array 3, [/SIZE][SIZE=10.5pt]to see if Player has been to those coordinates before.[/SIZE]

[SIZE=10.5pt]Step 4: If the Player has been to those Global Coordinates before:[/SIZE]

[SIZE=10.5pt]1) The program checks[/SIZE][SIZE=10.5pt] Array 5 [/SIZE][SIZE=10.5pt]for Array 1 and extracts the Map ID. For[/SIZE] [SIZE=10.5pt]example, Player has been to [1, 0] and it loaded map 16, so the program will find [[/SIZE][SIZE=10.5pt][[/SIZE][SIZE=10.5pt]1, 0[/SIZE][SIZE=10.5pt]][/SIZE][SIZE=10.5pt], 16] in the array and then get the number 16.[/SIZE]

[SIZE=10.5pt]2) [/SIZE][SIZE=10.5pt]Player's Future Map ID [/SIZE][SIZE=10.5pt]is updated with the ID extracted. [/SIZE]

3) Array 2 is set to Array 1

[SIZE=10.5pt]4) The player is transferred to the map. [/SIZE](That process has already been discussed earlier in this thread)

[SIZE=10.5pt]If the Player has not been to those Global Coordinates before:[/SIZE]

[SIZE=10.5pt]1) A random number is generated and [/SIZE][SIZE=10.5pt]Player's Future Map ID [/SIZE][SIZE=10.5pt]is updated with that number.[/SIZE]

2) The program adds Array 1 to Array 3

3) The program overwrites Array 4 with Array 1 and Player's Future Map ID.

4) The program adds Array 4 to Array 5

5) The program loads a Map based on the random number.

6) Array 2 is set to Array 1.

7) The player is transferred to the map.

Okay so that was pretty intense stuff.

I used a lot of resources:

Especially the Ruby documentation on Arrays: http://ruby-doc.org/core-2.0/Array.html

I also used the built in resources with RPG Maker VX Ace software. (the help section)

The commands I used:

push: To add information to the Arrays I used push, for example array3.push(array1) will add array 1 to the end of array 3.

include: To check for information in an Array I used the include command, for example if array3.include?(array1) then ... else ... end (fill in the ... with the commands)

assoc: To extract an Array from an Array I used the assoc command, for example array5.assoc(array1) will extract an entire array, meaning it will pull out something that looks like array4 if it exists within array5

at: To pull information from an Array I used the at command, for example array4.at(1) will extract the Map ID.

Things to keep in mind:

ruby is case sensitive so if you capitalize any of your words while writing in the script column ruby will think you're referring to a global variable instead of something local.

I've attached some of my code as an example, hopefully it will help anyone coming here with similar problems.

Arrays.png
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-do-i-access-map-data-in-order-to-automate-transfer-coordinates.25647/