Huh?

Error message

Deprecated function: implode(): Passing glue string after array is deprecated. Swap the parameters in drupal_get_feeds() (line 394 of /var/www/pied-piper.ermarian.net/includes/common.inc).
AuthorTopic: Huh?
Infiltrator
Member # 5576
Profile Homepage #0
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?

--------------------
Überraschung des Dosenöffners!
"On guard, you musty sofa!"
Posts: 627 | Registered: Monday, March 7 2005 08:00
...b10010b...
Member # 869
Profile Homepage #1
Mind posting the script so that we can see what the heck might be going on?

--------------------
The Empire Always Loses: This Time For Sure!
Posts: 9973 | Registered: Saturday, March 30 2002 08:00
Infiltrator
Member # 5576
Profile Homepage #2
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.
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 completion
beginstate 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.

--------------------
Überraschung des Dosenöffners!
"On guard, you musty sofa!"
Posts: 627 | Registered: Monday, March 7 2005 08:00
...b10010b...
Member # 869
Profile Homepage #3
beginstate INIT_STATE;
-snip-
if(s == 0)
s = 2;
break;
First possible problem: you're not supposed to check the value of an uninitialised variable, and you haven't set s to anything before this point, so s is uninitialised.

I'll tell you if I spot anything else.

[ Saturday, October 15, 2005 20:29: Message edited by: Thuryl ]

--------------------
The Empire Always Loses: This Time For Sure!
Posts: 9973 | Registered: Saturday, March 30 2002 08:00
Infiltrator
Member # 5576
Profile Homepage #4
However that check has also proven to make no difference. I'll take it out for sure though.

--------------------
Überraschung des Dosenöffners!
"On guard, you musty sofa!"
Posts: 627 | Registered: Monday, March 7 2005 08:00
...b10010b...
Member # 869
Profile Homepage #5
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.

[ Sunday, October 16, 2005 04:56: Message edited by: Thuryl ]

--------------------
The Empire Always Loses: This Time For Sure!
Posts: 9973 | Registered: Saturday, March 30 2002 08:00
Infiltrator
Member # 5576
Profile Homepage #6
Yes, originally the variable's name was 'state' and that totally messed the script up so that it wouldn't run. I have also tried changing it to 'k', and there is no difference.

--------------------
Überraschung des Dosenöffners!
"On guard, you musty sofa!"
Posts: 627 | Registered: Monday, March 7 2005 08:00