Recursive functions not working?

razorboy

Member
I'm working on a hobo-killing script that will cast spells until my MP is low, then switch outfits to mp regen, casting moxious maneuver until my mp is up again. Rinse, repeat. But I'm getting an odd recursion error. Here's my code:

Code:
void hobo_cast() {
    if (my_adventures() == 0) {
        abort("Out of adventures.");
    }
    cli_execute("outfit Hobopolis Regen");
    repeat { adventure(1 , $location[hobopolis town square]);
    } until (my_mp() <= 120);
    cli_execute("ccs hobo_attack");
    hobo_attack();
}

void hobo_attack() {
    if (my_adventures() == 0) {
        abort("Out of adventures.");
    }
    cli_execute("outfit Hobopolis Moxie");
    repeat { adventure(1 , $location[hobopolis town square]);
    } until (my_mp() > 600);
    cli_execute("ccs hobo_cast");
    hobo_cast();
}
 
void main() {
        cli_execute("ccs hobo_cast");
        hobo_cast();
}

the error I get is:
Function 'hobo_attack( )' undefined.

What am I doing wrong here? I think this should be ok. (Other hints on cleaning up my code appreciated!)
 

Bale

Minion
That has nothing to do with it being recursive and it isn't really recursive.

You cannot call a function that is declared after it is called. To make it work, at the top of the program define it by putting this line:

Code:
void hobo_attack();

Though it would be better to rewrite it as a single function which changes outfits and CCS depending on your current mp. For what it is worth, this is how I might write that:

PHP:
boolean cast;

void hobo_cast() {
	set_property("customCombatScript", "hobo_cast");
	outfit("Hobopolis Regen");
	cast = true;
}

void hobo_attack() {
	set_property("customCombatScript", "hobo_attack");
	outfit("Hobopolis Moxie");
	cast = false;
}

void hobo_adventure() {
	hobo_cast();	
	while(my_adventures() > 0) {
		if(cast && my_mp() <= 120)
			hobo_attack();
		else if(!cast && my_mp() > 600)
			hobo_cast();
		adventure(1 , $location[hobopolis town square])
	}
}

void main() {
	hobo_adventure();
}
 
Top