Creating a list of Fast Travel Locations

I'm trying to create a fast travel plugin and in order to do so I need to build a list of locations that are associated with a Location Name, Map ID, Map X co-ordinate and Map Y co-ordinate.

Would anyone be able to point in the right direction of

1. How do I push these four variables to a list?

2. How would I retrieve the Map ID, Map X and Map Y for the location?

Any help is appreciated  😀
Well, what you could do is to have an array of objects, or array of arrays.

I *think* you can do such thing with defining your locations in JSON file, and reading from JSON file with JsonEx...

And for retrieving, if you are defining them in JSON file it'll look like :

[ { name: Locaction1, mapiD: 10, x: 123, y: 456, }, etc.]And after reading from file you'll be able to retrieve them with yourListOfLocations[index], and if you want to retrieve location's name it'll be yourListOfLocations[index].nameI just think this would be the best way, because when defining an infinite amount of something in JGSS there are two approaches : in JSON and in notetag.

In RGSS we had config modules...
Could I not store the variables as plugin parameters already set up? Then transform the parameters into the arrays?
Well, you can store JSON in the plugin parameter...

But, if user of the plugin wants 100 fast travel location, what then?

Are you going to make 100 plugin parameters?

And what if some other user want 101 locations?

That's the problem with storing data that can have infinite dimensions in something such as plugin parameters that are finite.

Of course, you can store ALL locations in one plugin parameter, as JSON, but who would read that?

What would happen if somebody made a mistake and he needs to look through 100 characters all on one line just to find out he forgot a comma?
I see. I was just going to use this for myself so I would know how it works and what to do, but I see your point. It doesn't make sense to do it that way if there will be lots of locations. You'll have to forgive me if this question is simple, I'm new to Javascript. How would I create the JSON file?
use $gameMap or $gameMaps to get a series of maps, then you can set those as locations to teleport to
Why can't you just generate the list using 1 plugin command? Seems simple to do. Just have a command that adds a fast travel location to the array of objects. I don't see a need to use JSON or anything else.
@Jeremy Cannady

It's possible with a common event, and some scripting, but it may cause lagg.

I'm not sure how much lagg, but I'm sure that is unoptimal.

But simple.

@beenbaba

To create a JSON file, go to your project anywhere, possibily in data folder, and create a file with extension .json

You can find more about JSON syntax here.

Now, you can load JSON file into your object with DataManager.loadDataFile(nameofyourobject, sourceofyourobject);

Like :

var $dataLocations;DataManager.loadDataFile('$dataLocations', 'nameofyourfile.json');Of course, those two mustn't be one after another, because you'll get an error where DataManager is undefined or sometimg like that...The second command you should put in some method that will execute after loading of the database.

You can also try Jeremy's option, where you would need to alias methods in Scene_File and Game_Interpreter, but it should be simpler.
@Jeremy Cannady

I tried doing it this way and it worked, for the most part. The issue I had was when I added a location using the plugin command, saved the game, exited, then reloaded the game anything I added using the command would disappear. Presumably because what I have added to the array had not been saved anywhere, which is what I assume KockaAdmiralac meant by aliasing the Scene_File, correct me if I'm wrong.
Yes, you should make a common event which you will call on game load/new game.

Actually, you could do that in Scene_Title if Continue/New Game is selected.

How many stations did you add?

Was it laggy while adding them?

Because I'm not sure what is laggy in JS...
I added 2 so not many at all but I didn't experience any lag. Although, my PC spec I imagine isn't the typical set up a user would have so that may influence things.

What I do in the common event, run all the plugin commands?
Yes.

Also, I think you can reserve execution of a common event with

Code:
$gameTemp.reserveCommonEvent(common_event_id)
Is there no way to just save what is currently in the list? So it's stored for when the game continues so I can run the plugin command dynamically as and when I need to instead of specifying all of the fast travel locations from the start? Would, like you said in the beginning about the JSON file, be the only way?
Can't you just make it apart of Game Player? It should save what you have made in there.
@beenbaba

If you want to store that data you would store it as JSON, yes.

You can also, as Jeremy said, store it in $gamePlayer/$gameMap etc.

In that case you would regularily call common event that generates your positions on the beginning of the game, and store it in some placeholder variable inside $gamePlayer.
Why would something like this not work?
If you want to add a location to the list then use the plugin command: addFastTravelLocation name mapID x y ---> addFastTravelLocation coolCity 7 15 19

Then to get the data write $gameParty._fastTravelLocations[name][0] is mapd id $gameParty._fastTravelLocations[name][1] is the x $gameParty._fastTravelLocations[name][2] is the y

Code:
Game_Party.prototype._fastTravelLocations = {};Game_Party.prototype.addLocation = function(name, mapId, x, y)={$gameParty._fastTravelLocations[name]=[mapId, x, y];};var addLocationsToList_pluginCommand = Game_Interpreter.prototype.pluginCommand;Game_Interpreter.prototype.pluginCommand = function(command, args) {	addLocationsToList_pluginCommand.call(this, command, args);	if (command === "addFastTravelLocation") {		var arg1 = JSON.parse(args[0])		var arg2 = JSON.parse(args[1]);		var arg2 = JSON.parse(args[2]);		var arg2 = JSON.parse(args[3]);		$gameParty.addlocation(arg1, arg2, arg3, arg4)	};};
Why would something like this not work?

If you want to add a location to the list then use the plugin command: addFastTravelLocation name mapID x y ---> addFastTravelLocation coolCity 7 15 19

Then to get the data write $gameParty._fastTravelLocations[name][0] is mapd id $gameParty._fastTravelLocations[name][1] is the x $gameParty._fastTravelLocations[name][2] is the y

Game_Party.prototype._fastTravelLocations = {};Game_Party.prototype.addLocation = function(name, mapId, x, y)={$gameParty._fastTravelLocations[name]=[mapId, x, y];};var addLocationsToList_pluginCommand = Game_Interpreter.prototype.pluginCommand;Game_Interpreter.prototype.pluginCommand = function(command, args) { addLocationsToList_pluginCommand.call(this, command, args); if (command === "addFastTravelLocation") { var arg1 = JSON.parse(args[0]) var arg2 = JSON.parse(args[1]); var arg3 = JSON.parse(args[2]); var arg4 = JSON.parse(args[3]); $gameParty.addlocation(arg1, arg2, arg3, arg4) };};
little ninja fix in your vars 😀
Thanks Jeremy! I get an unexpected token = for this bit though

Spoiler
Game_Party.prototype.addLocation = function(name, mapId, x, y)={

      $gameParty._fastTravelLocations[name]=[mapId, x, y];

};
Thanks Jeremy! I get an unexpected token = for this bit though

Spoiler
Game_Party.prototype.addLocation = function(name, mapId, x, y)={

      $gameParty._fastTravelLocations[name]=[mapId, x, y];

};
Try it without the "=" between the closing parenthesis and the opening bracket like this:

Code:
Game_Party.prototype.addLocation = function(name, mapId, x, y) {      $gameParty._fastTravelLocations[name]=[mapId, x, y];};
yeah shouldn't be that extra equal sign in there, typed to fast

This works for me.

Code:
(function(){Game_Party.prototype._fastTravelLocations = {};Game_Party.prototype.addLocation = function(name, mapId, x, y){	$gameParty._fastTravelLocations[name] = [mapId, x, y];};var addLocationsToList_pluginCommand = Game_Interpreter.prototype.pluginCommand;Game_Interpreter.prototype.pluginCommand = function(command, args) {	addLocationsToList_pluginCommand.call(this, command, args);	if (command === "addFastTravelLocation") {		var arg1 = JSON.parse(args[0])		var arg2 = JSON.parse(args[1]);		var arg3 = JSON.parse(args[2]);		var arg4 = JSON.parse(args[3]);		Game_Party.prototype.addLocation(arg1, arg2, arg3, arg4)	};};})();

Original thread: https://forums.rpgmakerweb.com/threads/creating-a-list-of-fast-travel-locations.50215/