Windows My character never stops losing HP

T

TheBlindG

Guest
Hello everyone!

I have a problem, I am trying to make some simple enemies for my turn based game. But the enemy, when it starts attacking me, My character never stops losing HP. I am not sure why he keeps doing that and was hoping any off you could understand my code n see why it's happening.

Here we go!

step event for character objects:
case "attack":
damage = floor((5 + pow) * dmg_mod);
attack_target.cur_hp -= damage;
attack_target = noone;

state = "end attack";
attack_timer = 30;
break;

case "end attack":
attack_timer -= 1;
if(attack_timer <= 0){
state = "end step";
}
break;


The attack player script:

scr_erange_indicator(ctr_combat.current_actor.number, ctr_combat.current_actor.range);

var targets = ds_list_create();

ds_list_add(targets, spot[4].actor);
scr_hit_check(ctr_combat.current_actor);
ctr_combat.current_actor.attack_target = Marcus;
ctr_combat.current_actor.state = "begin attack";
ctr_combat.current_actor.attack_timer = 10;
scr_whipe_spots();


ds_list_destroy(targets);
ctr_combat.current_actor = noone;

the range script and damage scripts work as they should so no need for me too show them.


the combat controller step event:

switch(state){

case "initialize":
state = "roll init";

break;

case "roll init":
temp_init = ds_priority_create();

//Call every actor, add themselves to queue
with(par_actor){
init_roll = irandom_range(1 + scen, 20 + scen);

ds_priority_add(other.temp_init, id, init_roll);
}

while(ds_priority_size(temp_init) > 0){
ds_list_add(turn_order, ds_priority_delete_max(temp_init));
}

turn_max = ds_list_size(turn_order);

ds_priority_destroy(temp_init);

state = "ready";

break;

case "ready":
if (current_actor = noone){
turn_counter++;

if (turn_counter >= turn_max){
turn_counter = 0;
round_counter++;
}

current_actor = ds_list_find_value(turn_order, turn_counter);

if(instance_exists(current_actor)){

if(current_actor.army = PLAYER){
ctr_cursor.selected_actor = current_actor;
}else{
TestAI();
}
}else{

This checks if the current actor is a player or not, if not player, it should do the script and go back to the next character in order.

So somehow after the enemy has acted, my hero never stops losing Hp

current_actor = noone;
}

}
break;
}


Hope someone can see what is going wrong with this.

Thanks in advance!
 
T

TDSrock

Guest
Seems like you just need to be setting damage back to 0 where applicable.
 
T

TheBlindG

Guest
Seems like you just need to be setting damage back to 0 where applicable.
Eventhough I de-select the attack_target?

Tried setting dmg back to 0, but still keeps dealing dmg

When my player attacks, he only deal damage once, here is his script:

if(instance_position(x, y, par_actor)){
temp_actor = instance_position(x, y, par_actor)
if(temp_actor.valid_target){
scr_hit_check(selected_actor);
selected_actor.attack_target = temp_actor;
selected_actor.state = "begin attack";
selected_actor.attack_timer = 10;
scr_whipe_spots();
}
}

I tried mimicing it for the enemy.
 
Last edited by a moderator:
P

ParodyKnaveBob

Guest
First off, lemme use the [code][/code] tags to make this readable.

Code:
// step event for character objects:
//PKB: WAIT, HOW DOES THE SWITCH READ?
case "attack":
  damage = floor((5 + pow) * dmg_mod);
  attack_target.cur_hp -= damage;
  attack_target = noone;

  state = "end attack";
  attack_timer = 30;
  break;

case "end attack":
  attack_timer -= 1;
  if(attack_timer <= 0){
    state = "end step";
  }
  break;
Code:
// The attack player script:

scr_erange_indicator(ctr_combat.current_actor.number, ctr_combat.current_actor.range);

var targets = ds_list_create();

ds_list_add(targets, spot[4].actor);
scr_hit_check(ctr_combat.current_actor);
ctr_combat.current_actor.attack_target = Marcus;
ctr_combat.current_actor.state = "begin attack";
ctr_combat.current_actor.attack_timer = 10;
scr_whipe_spots();


ds_list_destroy(targets);
ctr_combat.current_actor = noone;

// the range script and damage scripts work as they should so no need for me too show them.
Code:
// the combat controller step event:

switch(state){

  case "initialize":
    state = "roll init";

    break;

  case "roll init":
    temp_init = ds_priority_create();

    //Call every actor, add themselves to queue
    with(par_actor){
      init_roll = irandom_range(1 + scen, 20 + scen);

      ds_priority_add(other.temp_init, id, init_roll);
    }

    while(ds_priority_size(temp_init) > 0){
      ds_list_add(turn_order, ds_priority_delete_max(temp_init));
    }

    turn_max = ds_list_size(turn_order);

    ds_priority_destroy(temp_init);

    state = "ready";

    break;

  case "ready":
    if (current_actor = noone){
      turn_counter++;

      if (turn_counter >= turn_max){
        turn_counter = 0;
        round_counter++;
      }

      current_actor = ds_list_find_value(turn_order, turn_counter);

      if(instance_exists(current_actor)){

        if(current_actor.army = PLAYER){
          ctr_cursor.selected_actor = current_actor;
        }else{
          TestAI();
        }
      }else{

        current_actor = noone;
      }

    }
    break;
}
// This checks if the current actor is a player or not, if not player, it should do the script and go back to the next character in order.

// So somehow after the enemy has acted, my hero never stops losing Hp
Code:
// When my player attacks, he only deal damage once, here is his script:

if(instance_position(x, y, par_actor)){
  temp_actor = instance_position(x, y, par_actor)
  if(temp_actor.valid_target){
    scr_hit_check(selected_actor);
    selected_actor.attack_target = temp_actor;
    selected_actor.state = "begin attack";
    selected_actor.attack_timer = 10;
    scr_whipe_spots();
  }
}

// I tried mimicing it for the enemy.
Now I'll take more of a look at it...

EDIT: It appears you have a nice plan, but there's a lot to account for that we're probably not even seeing. (Just for one example, you attack player script creates a ds_list, adds one element to it, executes two mystery scripts, and then unceremoniously destroys the ds_list without any other apparent modifications.) My stock answer in cases like this (which normally works like a charm) is just to ask, "Have you run this in the debugger paused, stepping into every line of code manually, watching where the logic goes and what the variables become?"

I hope this helps, ~nodnod~
Bob
 
Last edited by a moderator:
T

TheBlindG

Guest
First off, lemme use the [code][/code] tags to make this readable.

Code:
// step event for character objects:
//PKB: WAIT, HOW DOES THE SWITCH READ?
case "attack":
  damage = floor((5 + pow) * dmg_mod);
  attack_target.cur_hp -= damage;
  attack_target = noone;

  state = "end attack";
  attack_timer = 30;
  break;

case "end attack":
  attack_timer -= 1;
  if(attack_timer <= 0){
    state = "end step";
  }
  break;
Code:
// The attack player script:

scr_erange_indicator(ctr_combat.current_actor.number, ctr_combat.current_actor.range);

var targets = ds_list_create();

ds_list_add(targets, spot[4].actor);
scr_hit_check(ctr_combat.current_actor);
ctr_combat.current_actor.attack_target = Marcus;
ctr_combat.current_actor.state = "begin attack";
ctr_combat.current_actor.attack_timer = 10;
scr_whipe_spots();


ds_list_destroy(targets);
ctr_combat.current_actor = noone;

// the range script and damage scripts work as they should so no need for me too show them.
Code:
// the combat controller step event:

switch(state){

  case "initialize":
    state = "roll init";

    break;

  case "roll init":
    temp_init = ds_priority_create();

    //Call every actor, add themselves to queue
    with(par_actor){
      init_roll = irandom_range(1 + scen, 20 + scen);

      ds_priority_add(other.temp_init, id, init_roll);
    }

    while(ds_priority_size(temp_init) > 0){
      ds_list_add(turn_order, ds_priority_delete_max(temp_init));
    }

    turn_max = ds_list_size(turn_order);

    ds_priority_destroy(temp_init);

    state = "ready";

    break;

  case "ready":
    if (current_actor = noone){
      turn_counter++;

      if (turn_counter >= turn_max){
        turn_counter = 0;
        round_counter++;
      }

      current_actor = ds_list_find_value(turn_order, turn_counter);

      if(instance_exists(current_actor)){

        if(current_actor.army = PLAYER){
          ctr_cursor.selected_actor = current_actor;
        }else{
          TestAI();
        }
      }else{

        current_actor = noone;
      }

    }
    break;
}
// This checks if the current actor is a player or not, if not player, it should do the script and go back to the next character in order.

// So somehow after the enemy has acted, my hero never stops losing Hp
Code:
// When my player attacks, he only deal damage once, here is his script:

if(instance_position(x, y, par_actor)){
  temp_actor = instance_position(x, y, par_actor)
  if(temp_actor.valid_target){
    scr_hit_check(selected_actor);
    selected_actor.attack_target = temp_actor;
    selected_actor.state = "begin attack";
    selected_actor.attack_timer = 10;
    scr_whipe_spots();
  }
}

// I tried mimicing it for the enemy.
Now I'll take more of a look at it...

EDIT: It appears you have a nice plan, but there's a lot to account for that we're probably not even seeing. (Just for one example, you attack player script creates a ds_list, adds one element to it, executes two mystery scripts, and then unceremoniously destroys the ds_list without any other apparent modifications.) My stock answer in cases like this (which normally works like a charm) is just to ask, "Have you run this in the debugger paused, stepping into every line of code manually, watching where the logic goes and what the variables become?"

I hope this helps, ~nodnod~
Bob

Cheers, I learned how to use the debugger in gamemaker now, and found to problem, I did pass off the current_Actor before the loop had finished, so it kinda looped all over and thought the enemy was the first in order to act
 
P

ParodyKnaveBob

Guest
Great! Glad to hear. $:^ ]

Now just remember to edit the first post to change the thread's prefix from Windows to SOLVED. $:^ ]
 
Top