Random Generated Pathway

Hello everyone. I want to connect roads in a random generated way so that every time a player goes in that road, it sets the pathway (replayability value). Maps have 2 or 3 exit points and my initial thought was to work as follow:

* Set for every map a variable equal to map number assigned (map 1 -> variable 1 =0; map 2 -> variable 1 = 1; ... ; map 20 --> variable 1 = 19).

* Then track the map sequence which is generated by the path:
e.g Map 1 -> Map 3 -> Map 11 -> Map14

But this would work only in a linear road. However when the Maps splits in three it's way more difficult:
e. g.
Map 1 -> Map 3 -> Map 11 -> Map14 ->
Map 1 -> Map 3 -> Map 4 -> Map 6 ->

How can I store the sequence generated ? e.g. 3, 6, 16, 17, 2, 1, 7, 11 and so on, in the specific order?

My idea was then: instead of tracking the map sequence, it should be set and stored the teleport location connections.

e.g.
Map 3 X,Y (1, 0) & Map 6 X, Y (18, 17);
Map 2 X, Y (5, 6) & Map 11 (11, 10);
.....;
Map 16 X, Y (15, 46) & Map 4 (13, 6);

In this perspective, there's a set of coordinates which are corresponding to teleports in each map and they need to match each other in a logic direction.


* What is the smartest and most efficient way for realize this by just eventing the whole problem?

* How many variables would be needed considering 1-20 Maps can exist at once and 90% of them have just 2 exit while 10% have 3 exits?

Here another approach to the same problem:

Another way could exist in:
- generate the sequence from a set (1, 2, 3, ..., 20)
- set teleport based on the sequence generated

But again I find difficult to track threeways back.

Another option:
* create a grid so that every map has three variables associated:
- map ID; grid coordinates; orientation (1-4)
Then another variable would decide the teleport X and Y, based on grid movements.

But still can't figure how to realize it by the least complication possible.
I assume you're talking about a constantly shifting maze-type of thing, right? If there's a definite limit to how many maps can be between one point and another, you could have that many variables set up in sequence, and store the map id of each link in the chain, so when you move along the path, you either grab the id of the previous link or the next one, depending on which exit you're at.

For three-exit paths? Depends on whether or not you can have multiple triple-exit maps in the same route. If not, another set of variables for THAT path. But if there is no structure to the possibilities, and literally ANY of the maps could appear at any point... the task is quite a bit harder.

Theoretically you could set a variable to your path as an array. It means using script, since variables can only be set to numbers through the editor, and with script variables can be literally anything you want.

Or just have the exits point to a random map EVERY time, making backtracking kind of useless. Then it'd be a case of "there are X maps along this path", where you just need to track how many maps along that path you are before instead moving to one of the path's end points. Of course you'd still need to track which direction you're moving in so someone doesn't just flip between maps to get to the end in a second or so.
The idea is to replicate the experience of Carcassonne where you can have multiple paths of the roads (i would map standardized pieces). However the limits should be:
- a start and an ending must exist
- threeways must have a end or a closed way (no half map left around)

Original thread: https://forums.rpgmakerweb.com/threads/random-generated-pathway.148067/