You can use the function "JSON.stringify()" to turn that into a standard javascript string that can be stored in a client variable, like this:var locations = ["Shallam", "Hashan", "Eleusis"];
Then, if you take a look at the variables tab in the client Settings, you should see something very much like what you started with:set_variable("visited_locations", JSON.stringify(locations));
["Shallam", "Hashan", "Eleusis"]
To actually use that as a real Javascript array again, you'll want to use the JSON.parse() function:
Which will let you do stuff like this:var locations_array = JSON.parse(get_variable("visited_locations"));
Since this method will result in client variables (again: those stored as part of your reflexes), when you save your system via the Settings window, it will permanently save the current state of all the variables you've built in this way.print(locations_array[1], "green"); // Will print "Hashan" to the output window //
Now, in this particular instance, you're not talking about a table that's going to change very often, so you can probably just code that directly into one of your scripts -- I just meant it as an example of what you CAN do with JSON.stringify/parse.var afflictions = [{name: "paralysis", cure_method: "eat", cure: "bloodroot", priority: 1000},{name: "anorexia", cure_method: "apply", cure: "epidermal", priority: 950} // etc.];set_variable ("affliction_table", JSON.stringify(afflictions));
Answers
With the answers to the two questions I think I can at least now code some persistance to my arrray/database.
One nagging doubt I have is size limits. I haven't even covered all of western Sapience yet (as defined by HELP GEOGRAPHY) and already my array is 1038 elements in size.
I'm currently using two arrays, an array of ids of locations visited and an array of names of locations visited. I doubt the numeric array will ever brake any limits, but I'm beginning to wonder when my location name array is going to break the line length limit of my editor. I use ActiveState's Komodo.
Line length is approximately 70,250 characters long so maybe 64k is the limit?
My editor Komodo was unphased (no clue what it's line length limit is but I'm sure it has one) and the import was successful (which should have failed if the line in question was split in two since both half-lines would be malformed) but when the function was run it failed with a syntax error.
I'll probably be fine with storing simply the room ids, but not the room names. Currently I use the GMCP Room.Info message to list the name of the known location names next to their respective exits.
Back to the drawing board.
That said, I'm fairly certain it's a line length limit since I've not had bother before when it was smaller and after importing the 70k line and checking it in the built-in settings editor it now shows on two lines (they're numbered so it's easy to spot).
I can provide an export of my settings if that will help and/or my external text file I use for import.
I've thought about breaking some of my settings up into packages. Can custom packages be referenced if I post them to a web server someplace? The three included packages all reside on Iron Realms servers.