Java script error. Where?

#1

Hey guys, i am having a java script error and i am not sure where. Included is the code and my error.

[05-08-2019 @ 20:36:25.911 GMT] [ERROR] [loadScript()@ScriptManager.java:46] Failed to load module: .\scripts\.\commands\catchCommand.js: JavaScript Error: missing formal parameter (catchCommand.js#6)
[05-08-2019 @ 20:36:25.913 GMT] [ERROR] [loadScript()@ScriptManager.java:49] Terminating PhantomBot due to Bad JavaScript File
(function() {
	var BASE_Pokemon = 400000;
	var BASE_VIEWER_EXP = 98000;
	var MAX_EXP = 10000;
	
	function experiencepokemon(sender, catch) {
		var currentEXP = parseInt($.inidb.get('catch', 'pokemonleft')),
			experience = parseInt($.inidb.get('catch', 'experience'));
		
		if(experience <= 0) {
			$.say('You are level 1 with no experience! Use !catch to level up!');
			return;
		}
		
		if(currentexperience < 1) {
			$.say('All Pokemon have been caught. The streamer must find the next field!');
			return;
		}
		
		if((currentEXP + catch) <= 0) {
			currentEXP = 0;
		} else {
			currentEXP = (currentEXP + catch);
		}
		
		if(currentEXP > 0) {
			$.say(sender + ' experience ' + catch + ' catch, leaving the field at ' + currentEXP + ' EXP!');
		} else {
			$.say(sender + ' caught ' + catch + ' experience, and cleared the field!');
		}
		
		$.writeToFile('' + currentEXP, 'EXP.txt', false);
		$.inidb.set('catch', 'EXP', currentEXP);
	}
	
	function attackUser(sender, stole) {
		var currentEXP = parseInt($.inidb.get('catch', 'experience'));
		
		if(currentEXP < 1) {
			$.say('You do not have any experience to catch the pokemon! Use !catch to gain EXP!');
			return;
		}
		
		if((currentEXP + catch) <= 0) {
			currentEXP = 0;
		} else {
			currentEXP = (currentEXP + catch);
		}
		
		if(currentEXP > 0) {
			$.say(sender + ' fails to catch the pokemon and takes ' + catch + ' damage as a result, leaving the Viewer EXP at ' + currentEXP + '!');
		} else {
			$.say(sender + ' failed to catch the pokemon. The pokemon retaliates with a ' + catch + ' damage hit, and has defeated the viewers!');
		}
		
		$.writeToFile('' + currentEXP, 'experience.txt', false);
		$.inidb.set('catch', 'experience', currentEXP);
	}
	
	function restoreEXP(sender) {
		var experience = parseInt($.inidb.get('catch', 'experience')),
			increase = $.randRange(1, 10000);
		if(experience >= BASE_VIEWER_EXP) {
			$.say('You cannot gain any experience at this time');
			return;
		}
		
		if((experience + increase) > BASE_VIEWER_EXP) {
			experience = BASE_VIEWER_EXP;
		} else {
			experience = (experience + increase) ;
		}
		$.writeToFile('' + experience, 'experience.txt', false);
		$.inidb.set('catch', 'experience', experience);
		$.say(sender + ' has healed the Viewers by ' + increase + '! Bringing the current health to ' + experience + '!');
	}
	
    /**
     * @event command
     */
    $.bind('command', function(event) {
        var sender = event.getSender().toLowerCase(),
            command = event.getCommand(),
            args = event.getArgs(),
            action = args[0],
			EXP = $.randRange(1, MAX_EXP);
			
        if (command.equalsIgnoreCase('catch')) {
			if(!action) {
				if($.randRange(1, 50) <= 25) {// about a 50/50 shot they attack
					catch(sender, hit);
				} else {
					attackUser(sender, hit);
				}
			} else if(action.equalsIgnoreCase('reset')) {// admin only reset command.
				$.inidb.set('catch', 'EXP', BASE_BOSS_EXP);
				$.inidb.set('catch', 'experience', BASE_VIEWER_EXP);
				$.writeToFile('' + BASE_POKEMON_EXP, 'EXP.txt', false);
				$.writeToFile('' + BASE_VIEWER_EXP, 'experience.txt', false);
			} else {
				$.say(sender + ', invalid option passed to catch command');
			}
        } else if (command.equalsIgnoreCase('potion')) {
			restoreEXP(sender);
		}
    });
    
    /**
     * @event initReady
     */
    $.bind('initReady', function() {
        if ($.bot.isModuleEnabled('./commands/catchCommand.js')) {
            $.registerChatCommand('./commands/catchCommand.js', 'potion', 7);
            $.registerChatCommand('./commands/catchCommand.js', 'catch', 7);
            $.registerChatSubcommand('catch', 'reset', 1);
        }
		var currentEXP = parseInt($.inidb.get('catch', 'EXP'));
		var exists = isNaN(parseInt(currentEXP)) || parseInt(currentEXP) === 0 ? (currentEXP = 0, true) : (false);
		if(!exists || currentEXP == 0) {
			$.inidb.set('catch', 'EXP', BASE_POKEMON_EXP);
			$.inidb.set('catch', 'experience', BASE_VIEWER_EXP);
			$.writeToFile('' + BASE_POKEMON_EXP, 'EXP.txt', false);
			$.writeToFile('' + BASE_VIEWER_EXP, 'experience.txt', false);
		}
    });
})();
#2

Hello superboy60,

Your code seems to be using a reserved JavaScript keyword, the keyword catch cannot be used as a variable as it is reserved for other purposes.

Here’s a list of reversed words in JavaScript
http://www.javascripter.net/faq/reserved.htm

Hope this helps!

#3

That helped but now i am seeing [05-08-2019 @ 22:32:53.527 GMT] [ERROR] [init.js:325] Error with Event Handler [initReady] Script [./commands/catchComma > init.js:445] Exception [ReferenceError: “BASE_POKEMON_EXP” is not defined.]

any idea what that means? at the top i have the var BASE_VIEWER_EXP = 98000; and ive tried var BASE_VIEWER_EXP = 1; but neither work

#5

Hey superboy60,

Make sure that your top variable name BASE_Pokemon is renamed to BASE_POKEMON_EXP.

Hope this helps!