Oh wow that was a pretty terrible menu design. See, what you were doing was creaing a bunch of objects in Menu() at the begenning and no sooner than using them you throw them away. In JS, just like in most languages objects you create within the scope of a function are deleted right after the function ends.
// the gist of what you are doing:
function Show()
{
function do_stuff() {
//...
}
var party = [];
CreateParty(party);
do_stuff(party);
}
SetUpdateScript("Show();");
The problem with the above is that each time you call Show, a party is created, displayed and then at that last '{' bracket, the party is destroyed. The next time you see the party you have different stats, not only that you can't level up or add or remove stats.
You were also creating local functions in a continuously updating loop. I figured that would have a huge impact on the FPS and it did, your maximum FPS is 900 on my machine, with my code fix it's at over 1800. I'll attach my fixes, they aren't pretty but it solves the problem. Basically I just created a single initializer, it runs once to add the info and then that's it. Ideally you want to have a global manager do this stuff for you. What happens if you need to add 3 hp to the 4th party member? It's not that easy in your design. In fact your menu shouldn't contain the actual items/party members/etc. Only represent them. Code design can be harder than the actual programming. You have to identify the code flow and know what values must persist (and this stay in the global scope) and what values can be thrown away.
I'd create a global static variable that holds all of the party info and then use that variable in my menu code to display party members.
Example, based on your code ideas:
var PartyManager = (function() {
var members = [];
var exp = Exponential(10);
members[0] = new Player("name_here", 85, 6, 45, 4);
MapOn(members[0].stats, [2, 3, 5, 6, 8], function() { return exp; });
var exp = Exponential(10);
members[1] = new Player("name_here", 85, 6, 45, 4);
MapOn(members[1].stats, [5, 6, 7, 9, 10], function() { return exp; });
return {
players: members,
money: 0,
}
}());
Abort(PartyManager.players[0].name);
If you ever have to do something like this:
Menu.party[4].hp += 3;Then that's bad design, it should be something like:
PartyManager.player[4].hp += 3;And the menu would have the changes automatically. In fact you should be able to create and throw away menus without affecting the party/items/etc in any way.