Jump to content

what's wrong with this code?

Recommended Posts

At the risk of making a pest of myself, I'd like to know why this doesn't work. smile I decided to code around the problem with damage_near_loc passing through walls, and came up with this:


beginstate 3; // attacking	...stuff here that's ok...			// time to spit more poison?	if (tick_difference(last_abil_time, get_current_tick()) > 1) {		// don't use damage_near_loc, because it damages where it shouldn't		i = 0;		while (i < 4) {			distance = char_dist_to_loc(i, my_loc_x(), my_loc_y());			if (distance == 1) {	// character is adjacent				print_named_str(ME, "spits poison!");				play_sound(42); // acid hiss				damage_char(i, get_ran(3, 1, 3), 2);			}			i = i + 1;		}	}		do_attack();break;
That seems to me as if it should work, but any character that's adjacent ends up taking damage four times, instead of only once. So where did I go wrong?




EDIT: DOH! It's always the simple gotchas. laugh Adding last_abil_time = get_current_tick(); before the last curly bracket makes it work as expected. Sorry 'bout dat!

Link to comment
Share on other sites

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