Jump to content

Huh?


Niemand

Recommended Posts

I have encountered a very odd problem working on a script: To begin with, my script was crashing occasionally, so I wanted to look into it. It looked like there was a bug that was causing it to run sate 5 sometimes where it shouldn't have, so I started looking into which states were running when. I discovered that the script would, on seeing an enemy, correctly go from state 2 (START_STATE) to state 5, then to state 3. But before it even got to the first bad behavior I had wanted to analyze, I saw that when it was supposed to be in state 3, it would run state 2 half a dozen times, and then state 3. When I tried to use a variable to keep track of what state it was in and have state 2 only do anything if the variable was 2, state 2 kept running anyway, When I examined the values of the variable, I saw that it was switching to 2 when it reached state 2 even though the only time in the script when that variable was assigned that value was in the INIT_STATE, which was not being rerun. I'd swear that variable is changing by itself.

 

Has anybody else ever seen anything like this at all?

Link to comment
Share on other sites

I hadn't originally because the relevant portion is basically all of it, and it is a bit long and messy since I'm still trying to get it in working order. I'm going to cut out most of the actual computation since, hopefully, it isn't significant to the problem.

Code:
 begincreaturescript;variables;short i,target,j,return,attackstate;short fire, ice, nonelem, summon, ment, blhe;short m, p, ltick, maxe, s;body;beginstate INIT_STATE;	if (get_memory_cell(0) == 2)		set_mobility(ME,0);	if (get_memory_cell(4) == 0)		set_memory_cell(4,3);	m = get_stat(ME,11);	p = get_stat(ME,12);	if((m > 0) || (p > 0))		attackstate = 5;	else		attackstate = 4;	maxe = get_stat(ME,36);	ltick = 0;	print_num(s);	print_str_color("s0",1);	if(s == 0)		s = 2;break;beginstate DEAD_STATE;	// Set the appropriate stuff done flag for this character being dead	if ((get_memory_cell(1) != 0) || (get_memory_cell(2) != 0))		set_flag(get_memory_cell(1),get_memory_cell(2),1);break;beginstate START_STATE; 	print_num(s);	//s = 6;	if(s == 2){	print_str_color("s2",1);	// if I have a target for some reason, go attack it	if (target_ok()) {		if ((dist_to_char(get_target()) <= 16) && ((get_flag(299,26) == 0) || (char_in_group(get_target(),0) == 0))){			return = 3;			set_state(attackstate);		}		else 			set_target(ME,-1);	}		// Look for a target, attack it if visible	if (select_target(ME,8,0)) {		if((get_flag(299,26) > 0) && (char_in_group(get_target(),0) == 1)){			select_target(ME,8,0);			if((char_in_group(get_target(),0)))				set_target(ME,-1);			else{				do_attack();				return = 3;				set_state(attackstate);			}		}		else{			do_attack();			return = 3;			set_state(attackstate);		}	}			// Have I been hit? Strike back!	if (who_hit_me() >= 0) {		set_target(ME,who_hit_me());		do_attack();		return = 3;		set_state(attackstate);	}			// Otherwise, just peacefully move around. Go back to start, if I'm too far	// from where I started.	if ((my_dist_from_start() >= 6) || ((my_dist_from_start() > 0) && (get_memory_cell(0) > 0))) {		if (get_ran(1,1,100) < 40) 			return_to_start(ME,1);		}		else if (get_memory_cell(0) == 0) {			fidget(ME,25);		}	// if we're in combat and the above didn't give me anything to do, just	// stop now. Otherwise, game will keep running script, and that eats up CPU time.	if (am_i_doing_action() == FALSE)		end_combat_turn();	}break;beginstate 3; // attacking	print_num(s);	print_str_color("s3",1);	s = 3;	if(get_current_tick()!=ltick && get_energy(ME)<maxe){		change_char_energy(ME,1);		ltick=get_current_tick();	}	if(get_energy(ME)<2){		end_combat_turn();	}	if (target_ok() == FALSE){		//s = 2;		set_state(START_STATE);	}	do_attack_tactic(2);break;beginstate 4; //non magical attacking	print_num(s);	print_str_color("s4",1);	s = 4;	if (target_ok() == FALSE){		//s = 2;		set_state(START_STATE);	}	do_attack();break;//REQUIRES: return is the state to go to on completionbeginstate 5; //sets spells for this target	print_num(s);	print_str_color("s5",1);	s = 5;	//-Massive amounts of code were removed here-	set_state_continue(return);break; 
In states 3 and 4, the assignments to s should not be commented out, normally, but I wanted to make utterly sure that they weren't responsible.
Link to comment
Share on other sites

It's a long shot, but have you tried changing the variable name to something else? I know there are some variable names that BoA won't let you use; maybe this is one that it does let you use but shouldn't.

 

Another thought: it's probably good form to replace all instances of ME with the my_number() call. ME sometimes misbehaves.

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
×
×
  • Create New...