Maximum call stack size exceeded (when attempting to alias Game_Actor setup or initialize methods)

Discussion in 'Javascript/Plugin Support' started by Feldherren, Oct 29, 2015.

  1. Feldherren

    Feldherren Veteran Veteran

    Messages:
    33
    Likes Received:
    11
    First Language:
    English
    I'm trying to rewrite a VXAce script of mine for MV, for practice and because one day I will probably want it for some project or another. Plus I had a grand total of one user back in VX Ace.

    The basic logic of the plugin (so far) is:

    Alias a suitable initialisation method for actors (here, Game_Actor.prototype.setup).

    Replace said method with my own.

    Call alias'd thing first, to get basic setup out of the way.

    Do stuff to swap out actor name with a randomly-picked name from lists.

    Voila, randomly-named actor.

    Unfortunately, whenever I try to run a game with this plugin enabled, I get the following error:

    RangeError: Maximum call stack size exceeded at file:///K:/Projects/RPG%20Maker/RPG%20Maker%20MV/RandomNames/js/rpg_objects.js:2400:18 at Array.reduce (native) at Game_Actor.Game_BattlerBase.traitsSet (file:///K:/Projects/RPG%20Maker/RPG%20Maker%20MV/RandomNames/js/rpg_objects.js:2399:30) at Game_Actor.Game_BattlerBase.isEquipWtypeOk (file:///K:/Projects/RPG%20Maker/RPG%20Maker%20MV/RandomNames/js/rpg_objects.js:2511:17) at Game_Actor.Game_BattlerBase.canEquipWeapon (file:///K:/Projects/RPG%20Maker/RPG%20Maker%20MV/RandomNames/js/rpg_objects.js:2809:17) at Game_Actor.Game_BattlerBase.canEquip (file:///K:/Projects/RPG%20Maker/RPG%20Maker%20MV/RandomNames/js/rpg_objects.js:2800:21) at Game_Actor.releaseUnequippableItems (file:///K:/Projects/RPG%20Maker/RPG%20Maker%20MV/RandomNames/js/rpg_objects.js:3666:32) at Game_Actor.initEquips (file:///K:/Projects/RPG%20Maker/RPG%20Maker%20MV/RandomNames/js/rpg_objects.js:3569:10) at Game_Actor.setup (file:///K:/Projects/RPG%20Maker/RPG%20Maker%20MV/RandomNames/js/plugins/RandomNames.js:69:10) at Game_Actor.initialize (file:///K:/Projects/RPG%20Maker/RPG%20Maker%20MV/RandomNames/js/rpg_objects.js:3394:10)rpg_managers.js:1618 SceneManager.catchExceptionAs you can see, it starts off trying to create actors as normal, and properly goes into my version of Game_Actor.setup to start doing normal setup stuff there. Then it eventually exceeds maximum call stack size.

    At first sight, this seemed like I'd accidentally bumped into the maximum call stack size by just adding one extra call - the alias'd thing, at the beginning. So to test this I did something that would normally be pretty dumb for compatibility reasons and just ditched the aliasing, putting the entire contents of Game_Actor.prototype.setup prior to my own code, for testing purposes.

    Unfortunately this didn't work and I got essentially the same error telling me I'm running past the maximum call stack size again.

    I can't see what is causing things to go wrong here, but I suspect it's something I've done and I'm clueless currently. Can anyone help me?

    Plugin code:

    Code:
    /*: * @plugindesc Allows actors and enemies to randomly pick a name from user-defined sets. * @author Feldherren * * @param Separator Character * @desc Separator character to use in name lists * @default , * * @param list1 * @desc First list of names that can easily be used for multiple units; default list is male names. Uses separator defined above. * @default Abel,Abelard,Abraham,[snip],Zerig * * @param list2 * @desc Second list of names that can easily be used for multiple units; default list is female names. Uses separator defined above. * @default Adela,Adelaide,Admiranda,[snip],Ysmeina * * @param list3 * @desc Third list of names that can easily be used for multiple units; default list is monster names. Uses separator defined above. * @default Achaios,Acis,Adonis,[snip],Zephyrus *  * @help This plugin does not provide plugin commands. Notebox tags: <name_list:list> Defines an actor or enemy as using the named list of random names,  for easy definition of commonly-used name lists. The lists 'list1', 'list2' and 'list3' are set up as parameters by default. <random_names:name,othername,anothername,etcetera> Defines a list of names for an actor or enemy to randomly be  initialised with, in the notebox. Uses the separator set in  plugin parameters. */ (function() { var parameters = PluginManager.parameters('RandomNames'); var _Game_Actor_setup = Game_Actor.prototype.setup; Game_Actor.prototype.setup = function(actorId) { 	_Game_Actor_setup.call(this, actorId); 	// read and switch names here 	var actor = $dataActors[actorId]; 	if (actor.meta.name_list) 	{ 		name_set = parameters[actor.meta.name_list].split(parameters['Separator Character']); 	} 	else if (actor.meta.random_names) 	{ 		name_set = actor.meta.random_names.split(parameters['Separator Character']); 	} 	else 	{ 		name_set = actor.name; 	} 	var choice = Math.random(); 	choice *= name_set.length; 	choice = Math.floor(choice); 	$gameActors.actor(actorId).setName(name_set[choice]) };})();
     
    Last edited by a moderator: Oct 29, 2015
    #1
  2. NoInkling

    NoInkling Veteran Veteran

    Messages:
    39
    Likes Received:
    9
    First Language:
    English
    I don't know if it will fix your problem, but shouldn't this line just be "this.setName(name_set[choice]);"?

    Edit: Just tried it out, that does seem to fix it. Looks like you were getting recursive there or something.
     
    Last edited by a moderator: Oct 29, 2015
    #2
  3. Feldherren

    Feldherren Veteran Veteran

    Messages:
    33
    Likes Received:
    11
    First Language:
    English
    That did fix the problem. Thank you.
     
    #3

Share This Page