Having trouble with inheritance

Hey

I have these characters (Brains) underneath an unbrella (SpecfialtyBrain) . Since I've switched over to this inheritance format I'm having all kinds of trouble.
Most of them I think its where the event_inherited(); are placed. But some are not.

PARENT CREATE


Code:
x = 0
y = 0

global.current_brain_specialty_target = 0
global.brain_party_still = noone;
global.brain_party_walk = noone;
global.brain_party_kill = noone;

decision_timer  = room_speed;
///Random path change for brains

path_change = room_speed*3;

attackTarget = noone;

floater_myTimer = room_speed;
//////////////////////////STATS/////////////////
///FOR INPUT INTO THE ALGORITHM////////

/////////////STRENGTH//////////////

global.brain_strength = 25;
/////////////////DEFENSE//////////////
global.brain_defense = 35;

//////////////////ATTACK/////////////////

global.brain_attack = 15;

//////////////////////DEXTERITY/////////////
//ability to use a projectile

global.brain_dexterity = 10;

/////////////////SPEED ///////////

//unaccelerated spaed


spd = 20;
//

global.brain_spd = 20;
/////////////INTELLIGENCE////////////////
//strength of projectiles

global.brain_intelligence = 10;

///////////EXPERIEINCE///////////////

//rolling over experience every time kill something with this bat type

global.brain_experience = 10;

///////////////LEVEL///////////////////////////

//experience adds up to a new level for that bat
//this increases stats for that bat type

global.brain_experience_level = 1;


////////////////////////////////GLOBAL RECEIVE HP DAMAGE//////////////////////////////

colliderbat = noone;
colliderbrain = noone;


intelligence = 10;


PARENT STEP

Code:
[4] = room_speed/4;

    //hp is incoming damage
    hp -= global.current_brain_specialty_target
    global.current_brain_specialty_target = 0
    ///////////////PAIRING///////////////////
    //////////////////////////////////////////

    attackRange = 50;
    flyspeed = 5;
    floater_myTimer--;

     //if attackTarget is empty
    if (!instance_exists(attackTarget))
    {
        //player presses mouse left
        if (mouse_check_button_released(mb_left))
        {
           //get a bat (was get a bat, now its brain parent
            attackTarget = instance_place(mouse_x, mouse_y, BatParentObject);
            //show_debug_message("Brain is attacking is : " + string(BatParentObject));
        }
    }

    //make sure thqt attackatarget has a reference
    if instance_exists(attackTarget)
    {
       //When decision_timer is set, count down the timer and clear the attackTarget and attacking
       if decision_timer > 0
       {
          decision_timer--;
          if (decision_timer == 0)
          {
              //brain is no longer attacking
              attackTarget = noone;
              attacking = false;
          }
       }
      
       else if distance_to_object(attackTarget) > attackRange //DECISION TIMER IS 0  AND BRAIN IS NO LONGER ATTCKING
       {//   BRAIN DISTANCE FROM BAT IS > attackRange
           //Far from brain, move towards it
            
            //{
                if attacking == false  //set attacking to false and
                                //move towrds bat
             move_towards_point(attackTarget.x,attackTarget.y, flyspeed);
            //}
          //Note: You could have the decision_timer code under an else-conditional here,
          //which would allow ranged brains to keep attacking until the bat leaves its range
       }
      else //BRAIN DISTANCE TIMER IS 0 AND BRAIN IS CLOSE TO BAT
            //LOCKING IN
            //assign attack target
            //or move towards target
            //or lock in battle
       {
           //LOCK IN BATTLE
        attacking = true;
        speed=0;
        other.speed = 0
        other.path_speed = 0
        //locked in
        //if global.colliderbat_temp  exists
        //attackTarget is assigned to global.colliderbbat_temp
        if (instance_exists(global.colliderbat_temp))
        {
            attackTarget = global.colliderbat_temp;
            show_debug_message("Brain locked onto attackTarget");
        }
       }
      
    } //end instancfe exits attacktarget

    else
    {
       attacking = false;
       //attackTarget = noone;
       decision_timer = 0;
    
    }
    //////////////////////////////////////////
    ///////////Deal Damage
    
    if distance_to_object(attackTarget) < attackRange
{
    //deal out damage to enemy brain
                
    //total damage to brain
    total_strength = global.bat_strength - global.brain_strength;
    total_defense = global.bat_defense - global.brain_defense;
    total_formula = (global.bat_strength - global.brain_defense)*global.bat_attack
    damage = total_formula*irandom_range(50, 75)/1000
    
    show_debug_message("Damage deal to bat" + string(damage))       
                    
    //clamping
    if (damage < 0)
    {
        damage = damage * -1;
    }
    
    ///calculate later
    global.current_bat_attack_target_damage = damage;
    /////////////STATUS EFFECTS///////////////
}
    
if (x < 200)        //Enemy Hit the Castle
{
    instance_destroy();
}
    
    //mindbreaker
if (global.mindbreak || global.mindbreaker)
{
    path_start(path30, 15, path_action_reverse, 0);
}



//was hit by a snowball
if (frozen)
{
    path_speed =0;
    speed = 0;
    sprite_index =SnowFrozenEnemy;
    alarm[9] = room_speed;
}

//petrified
if (global.petrification == true)
{
    path_speed = 0;
    speed = 0
    sprite_index = PetrifiedBrain;
}

if (global.freeze_brains)
{
    path_speed = 0;
    speed = 0;
    //sprite_index = BigBrainStill;
    alarm[9] = room_speed;
}

//hit by lightning
was_hit_by_lit = false;


defense = 1;
if (global.defense_boost)
{
    defense = 20;
}




//////////POISON INFLICTED////////////////
/////////////////////////////////////////

/////////////////////////////////
//Poison ZmyTimer
//


if (poisoned)
{
    
    myTimer--;
    if (myTimer <= 0)
    {
            total_strength = strength - other.strength
        total_defense = defense - other.defense
total_formula = (strength - defense)*attack
        hp_minus = total_formula*irandom_range(200, 400);
        
        hp_minus = damage;
        myTimer = 0;
        floater = instance_create_depth(x+10, y-10, -17000, DamageIndicatorObject);
        floater.text = string(hp_minus);
        
        if (hp <= 0)
        {
            show_debug_message("Dead Brain Ghost and Fading Gem");
            instance_create_depth(x, y, -1100,DeadBrainObject);       
            instance_create_depth(x-150, y-20, -1100, FadingGemObject);
            global.achievement_gold_counter++;
            
            with (other)
            {
                experience += 50
            }
            
            global.achievement_tome_experience += 20;
            instance_destroy();
        }
        myTimer = room_speed;
    }
    under_attack = true;
    took_a_hit = true;
}
    

attackRange = 50;
flyspeed = 5;
floater_myTimer--;



global.brain_strength = strength
/////////////////DEFENSE//////////////
global.brain_defense = defense

//////////////////ATTACK/////////////////

global.brain_attack = attack

//////////////////////DEXTERITY/////////////
//ability to use a projectile

global.brain_dexterity = dexterity

/////////////////SPEED ///////////

//unaccelerated spaed

global.brain_spd = spd

///////////////INTELLIGENCE////////////////
//strength of projectiles

global.brain_intelligence = intelligence

////////////////////////////////////////////



if (point_in_rectangle(x-100, y, 156, 100, 600, 1400))
{
    show_debug_message("Wall Collision");

    castle_wall_myTimer--;
    
    if (castle_wall_myTimer <= 0)
    {
    //    hp_minus = irandom_range(40, 150);
        hp_minus = irandom_range(200, 600);
        hp = hp - hp_minus
        global.castle_hp = global.castle_hp - hp_minus;
        path_end();
        
        
        //Trieed 500 unsuccesful. Try ing 600.
        //600 works but spans the whole level
        //trying 650
        if (x < 590 && x>200)  //tried 500 and 600. Tried 550.Tried 590. Tried 580
        {
            show_debug_message("Xdimensions IS " + string(x))
            with (ScorpionBrainObject)
            {
                sprite_index = ScorpionBrainAttack;
            }
        
            with (BigBrainObject)
            {
                sprite_index = BigBrainAttacking
            }
            while (damage_display <= room_speed*10)
            {
                damage_display++;
                floater = instance_create_depth(x,y, -1700, DamageIndicatorObject);           
                floater.text = string(hp_minus);
            }
        }
        
        
         instance_create_depth(x, y-300, -1800, FrankGhostObject);
         instance_destroy()
        //sprite_index = global.brain_party_kill;

        castle_wall_myTimer--;

        number_of_attacks++;

        //if (number_of_attacks > 5)
        //{
        //    instance_destroy();
        //}
    

        
        castle_wall_myTimer = room_speed;
        
        
        //floater = instance_create_depth(x+10, y-10, -17000, DamageIndicatorObject)    ;
        //floater.text = string(hp_minus);   
        show_debug_message("Iterating through step wall myTimer");
    }



}

/////////////////////////////////
/////////////LIGHTNING BAT ATTACK//////////////
/////////////////////////////////////////////

//show_debug_message("lit_damage_myTimera: " + string(lit_damage_myTimera));
//show_debug_message("lit_damage_myTimerb: " + string(lit_damage_myTimerb));
//show_debug_message("lit_damage_myTimerc: " + string(lit_damage_myTimerc));
if (global.active) { show_debug_message("Active is true"); }
else { show_debug_message("ACtive is false"); }
if (global.active == true && collision_line(global.litorigin_x, global.litorigin_y, global.lightning_1_x, global.lightning_1_y, ScorpionBrainObject, false, false))
{
    lit_damage_myTimera--;
    show_debug_message("lit_damage_myTimera: " + string(lit_damage_myTimera));
    if (lit_damage_myTimera <= 0)
    {
        
        show_debug_message("Lit myTimer A fire: ");
        total_strength = strength - other.strength
        total_defense = defense - other.defense
        total_formula = (strength - defense)*attack
        hp_minus = total_formula*irandom_range(100, 400);
        
        damage = hp_minus;
        hp = hp - hp_minus;
        floater = instance_create_depth(x, y, -17000, DamageIndicatorObject)   
        floater.text = string(damage)
    
        under_attack = true;
        took_a_hit = true;
        was_hit_by_lit = true;
        lit_damage_myTimera = room_speed*4;
        
    }
}


if (global.active == true && collision_line(global.lightning_1_x, global.lightning_1_y, global.lightning_2_x, global.lightning_2_y, ScorpionBrainObject, false, false))
{
    lit_damage_myTimerb--;

    if (lit_damage_myTimerb <= 0)
    {
        show_debug_message("Lit myTimer B fire: ");
                total_strength = strength - other.strength
        total_defense = defense - other.defense
        total_formula = (strength - defense)*attack
        hp_minus = total_formula*irandom_range(100, 400);
        
        damage = hp_minus;
        hp = hp - hp_minus;
        floater = instance_create_depth(x, y, -17000, DamageIndicatorObject)   
        floater.text = string(damage)
    
        under_attack = true;
        took_a_hit = true;
        was_hit_by_lit = true;
        lit_damage_myTimerb = room_speed*4;
    }
}


if (global.active == true && collision_line(global.lightning_2_x, global.lightning_2_y, global.lightning_3_x, global.lightning_3_y, ScorpionBrainObject, false, false))
{
    lit_damage_myTimerc--;
    if (lit_damage_myTimerc <=0)
    {
        
        show_debug_message("Lit myTimer C fire: ");
                total_strength = strength - other.strength
        total_defense = defense - other.defense
        total_formula = (strength - defense)*attack
        hp_minus = total_formula*irandom_range(100, 400);
        
        damage = hp_minus;
        hp = hp - hp_minus;
        floater = instance_create_depth(x, y, -17000, DamageIndicatorObject)   
        floater.text = string(damage)
    
        under_attack = true;
        was_hit_by_lit = true;
        lit_damage_myTimerc = room_speed*4;
    }

}

//////////////////Lightning Bat KIll////////////////////


if (hp <= 0)
{
    global.achievement_gold_counter++;
    global.achievement_tome_experience += 20;
    
    with (other)
    {
        experience += 30
    }
    
    audio_play_sound(DieingBrainSound, 20, false);
    instance_create_depth(x, y, -1100,DeadBrainObject);       
    instance_create_depth(x-150, y-20, -1100, FadingGemObject);
            
    instance_destroy();
            
}


if (poisoned == true)
{
    hp -= 100
   instance_destroy(PoisonBuffIcon)
   instance_create_depth(x, y-100, -1400, PoisonBuffIcon)
}



event_inherited();
STORMSPECIALBRAIN CREATE

Code:
global.brain_party_still = StormSpecialtyBrain;
global.brain_party_walk = StormSpecialtyBrainWalk;
global.brain_party_kill = StormSpecialtyBrain;


global.brain_strength = strength
/////////////////DEFENSE//////////////
global.brain_defense = defense

//////////////////ATTACK/////////////////

global.brain_attack = attack

//////////////////////DEXTERITY/////////////
//ability to use a projectile

global.brain_dexterity = dexterity

/////////////////SPEED ///////////

//unaccelerated spaed

global.brain_spd = spd

///////////////INTELLIGENCE////////////////
//strength of projectiles

global.brain_intelligence = intelligence

///////////EXPERIEINCE///////////////

//rolling over experience every time kill something with this bat type

global.brain_experience = experience

///////////////LEVEL///////////////////////////

//experience adds up to a new level for that bat
//this increases stats for that bat type

global.brain_experience_level = experience_level


///////////////damage/////////////////////
show_debug_message("DAMAGE" + string(global.current_brain_attack_target_damage));
if (global.current_brain_attack_target_damage > 0)
{
//direct damage works
//global.current_brain_attack_target_damage is 0
    hp -= 50;
    //hp -= global.current_brain_attack_target_damage;
    //global.current_brain_attack_target_damage = 0;     //reset damage
}




/////////////STRENGTH//////////////

event_inherited();

////mindbreaker

STORMSPECIALBRAIN STEP CODE
Code:
global.brain_party_still = StormSpecialtyBrain;
global.brain_party_walk = StormSpecialtyBrainWalk;
global.brain_party_kill = StormSpecialtyBrain;


global.brain_strength = strength
/////////////////DEFENSE//////////////
global.brain_defense = defense

//////////////////ATTACK/////////////////

global.brain_attack = attack

//////////////////////DEXTERITY/////////////
//ability to use a projectile

global.brain_dexterity = dexterity

/////////////////SPEED ///////////

//unaccelerated spaed

global.brain_spd = spd

///////////////INTELLIGENCE////////////////
//strength of projectiles

global.brain_intelligence = intelligence

///////////EXPERIEINCE///////////////

//rolling over experience every time kill something with this bat type

global.brain_experience = experience

///////////////LEVEL///////////////////////////

//experience adds up to a new level for that bat
//this increases stats for that bat type

global.brain_experience_level = experience_level


///////////////damage/////////////////////
show_debug_message("DAMAGE" + string(global.current_brain_attack_target_damage));
if (global.current_brain_attack_target_damage > 0)
{
//direct damage works
//global.current_brain_attack_target_damage is 0
    hp -= 50;
    //hp -= global.current_brain_attack_target_damage;
    //global.current_brain_attack_target_damage = 0;     //reset damage
}




/////////////STRENGTH//////////////

event_inherited();

////mindbreaker
 

Nidoking

Member
What's the actual problem? What's happening that you don't want to happen?

Also, I think you have some paste errors there. Part of the Parent Step event seems to be missing, and you pasted the child's Step event where you say it's the Create event (unless they're both identical, in which case, I think that may be part of the problem).

That's also a lot of global variables, many of which look like they should be instance-specific. If you've got more than one instance using those global variables, they're all going to share a value. That may or may not be what you want.
 
What's the actual problem? What's happening that you don't want to happen?

Also, I think you have some paste errors there. Part of the Parent Step event seems to be missing, and you pasted the child's Step event where you say it's the Create event (unless they're both identical, in which case, I think that may be part of the problem).

That's also a lot of global variables, many of which look like they should be instance-specific. If you've got more than one instance using those global variables, they're all going to share a value. That may or may not be what you want.
@Nidoking LIke I said (not clearly, I apologize) I had everything working and then I decided to use OO and then I created an umbrella class called SpecialBrain and all went to hell. Brains started stopping in their tracks when theiy collided and I can't kill them. Other brains just don't spawn at all. Some brains cause the player's bats to die and then the game to freeze up.

I used event_inherited to the best of my ability thinking that is the problem. Buy I still have the errors,. Oh and I want those globals
 

Nidoking

Member
I'm afraid to say that this doesn't sound like the kind of problem that can be solved on a forum. The problems you describe have wide scope and are clearly issues that cover the entire scope of your game. The only way to get to the root of the problems would be to debug heavily or to examine the entire game and find the flaws in the design. You're combining global variables with inheritance in ways that don't make sense to me. You're populating global variables from instance variables in a step event. You say "brains" plural meaning that there's more than one, and they're all sharing these global variables. I think your best option is to take your lessons learned and start from scratch, designing the inheritance in from the beginning. Otherwise, you'd have to send your entire game to someone if you expect them to help you. Posting portions is just not going to be enough.
 
Ok. I understand. I thought it would be fixable since one action (the parenting) caused all the brains to malfunction. I still think it can. I'll just have to revert.
 

curato

Member
my gut says you are misusing the global variables. the global is one public variable that spans the whole game you can't have a multiple objects change that to suit themselves and expect it to be there when they need it when multiple object types are changing the same variable. I am thinking you would need those to be scoped to the instance an then refer to them like instance.brain_party_walk if you need to refer to them out from another instance.
 
Hi Curato. What's the best to send a variable's value ( a message) in one event to another event. That's why I was using globals so superfluously.
 

TsukaYuriko

☄️
Forum Staff
Moderator
If that's events in the same object, declaring the variable under instance scope rather than global scope will make it available for the entire instance, separated for every instance of that object. To do that, remove the "global." prefix from the variable's name.
 

TsukaYuriko

☄️
Forum Staff
Moderator
In any context where you have access to the instance ID of whatever instance you are trying to "send a message" to, for example in a Collision event or when using the collision functions, you can use a with statement to change the scope of the code to that instance's scope. This will let you directly access and manipulate its variables.
 
In any context where you have access to the instance ID of whatever instance you are trying to "send a message" to, for example in a Collision event or when using the collision functions, you can use a with statement to change the scope of the code to that instance's scope. This will let you directly access and manipulate its variables.
Hmm...I didn't think of that. Thanks
 
I don't know how to work this,. I have this variable party_walk that holds the reference to the current sprite's animation. I have that variable so the BatParent and BrainParent have each have access to the current selected variable and sprite.
 

TsukaYuriko

☄️
Forum Staff
Moderator
What is the "message" you are trying to send from one to the other? Knowing that is crucial for us to be able to provide accurate advice.
 
bat parent inflicted damage ---> brain parent received damage
brain parent inflicted damage ---> bat parent received damage
that's an easy one
 
Another one:

GML:
if (mouse_check_button_released(mb_left))
{
    

  inst = instance_position(mouse_x, mouse_y, BrainParentObject)
  attackTarget = inst;
 
 //see how close you are to attackTarget
 if distance_to_object(attackTarget)<attackRange
 {
    if (inst.object_index != BrainParentObject && inst.object_index != BatParentObject)
    {   

          
       //end battle
        attacking = false;
        speed = 0;
        path_speed = 0;
        image_index = 0;
          
        //move_towards_point(mouse_x, mouse_y, flyspeed);
        with (attackTarget)
        {
                if attackTarget == other.id
                {
                decision_timer = room_speed+(image_number-image_index)*sprite_get_speed(sprite_index);
                }
        }
        //the party is static
        if(point_distance(x, y, inst.x, inst.y) < 20)
        {
                //sprite_index = global.party_walk;   
                sprite_index =global.party_still;
        }
     }
    
   }
}
 

chamaeleon

Member
Another one:

GML:
if (mouse_check_button_released(mb_left))
{
   

  inst = instance_position(mouse_x, mouse_y, BrainParentObject)
  attackTarget = inst;

//see how close you are to attackTarget
if distance_to_object(attackTarget)<attackRange
{
    if (inst.object_index != BrainParentObject && inst.object_index != BatParentObject)
    {  

         
       //end battle
        attacking = false;
        speed = 0;
        path_speed = 0;
        image_index = 0;
         
        //move_towards_point(mouse_x, mouse_y, flyspeed);
        with (attackTarget)
        {
                if attackTarget == other.id
                {
                decision_timer = room_speed+(image_number-image_index)*sprite_get_speed(sprite_index);
                }
        }
        //the party is static
        if(point_distance(x, y, inst.x, inst.y) < 20)
        {
                //sprite_index = global.party_walk;  
                sprite_index =global.party_still;
        }
     }
   
   }
}
Which piece of code in that snippet is not executing as expected, and what have you done to determine why the particular code path is not taken (in terms of variable values and function calls and if conditionals, not by looking at what happens on the screen)? Feel free to sprinkle show_debug_message() statements all over that outputting variables, object_index, instance ids, whether your inside an if statement due to a successful condition (and perhaps either add an else for a not inside if statement show_debug_message(), or a show_debug_message() after the whole if block and deduce you did not get inside it because you didn't get the inside message before the message after the if statement).

And before you say your project is so big, from where I'm sitting you have just posted what is supposed to be a relevant code snippet of only a few dozen lines. So debug the hell out of it and solve the problem at hand. Then move on to the next.
 
@TsukaYuriko Are you around? I need a handwit h the globals
Which piece of code in that snippet is not executing as expected, and what have you done to determine why the particular code path is not taken (in terms of variable values and function calls and if conditionals, not by looking at what happens on the screen)? Feel free to sprinkle show_debug_message() statements all over that outputting variables, object_index, instance ids, whether your inside an if statement due to a successful condition (and perhaps either add an else for a not inside if statement show_debug_message(), or a show_debug_message() after the whole if block and deduce you did not get inside it because you didn't get the inside message before the message after the if statement).

And before you say your project is so big, from where I'm sitting you have just posted what is supposed to be a relevant code snippet of only a few dozen lines. So debug the hell out of it and solve the problem at hand. Then move on to the next.
GML:
Which piece of code in that snippet is not executing as expected
I think the problem is with the "damage dealers" code. The pair code is supposed to lock the brain and bat and set them up for battle.
The pairing code does this: it detects a mouse click event. If the event has a BrainParent instance then ithe code should move the characters together and set the brain/bat attack targets. If you look at it its relatively concept-wise simple. Once the targets are paired it sends a message to the the opposing Bat/Brain Parent. The parents calculate the damage for that round, then continue until one character dies.

What happens on the screen:

Bat of your choice is dropped to the ground (left hand side),. Doc Frankenstein (right hand side .RIght hand side spawns a floating brain. The brain moves towards t he Draculas Castle. When they come in contact with each other the pairing code executes. Then they start the "damage dealing" happens. T hat's about it. What is happening though is the the brain and bat collide and just sit there; the and attack at all.

Bat Parent Object

Code:
///////////////////////////
//
//  Inheritance code
//
////////////////////////////



event_inherited()










//////////////////PARENTED FLIGHT/////////////////

if (flight == true)
    {
        
            if (point_distance(x, y, target_placement_x-100, target_placement_y-100) > 40)
            {
                sprite_index = global.party_walk;
                //image_index = 0;
                image_speed = 0.5;
                move_towards_point( target_placement_x-100, target_placement_y-100, spd );   
                global.dropped_bat = false;
                play_myTimer--;
                    if (played == false)
                    {
                        audio_play_sound(BatWingsMovementSound, 20, false);
                        played = true;
                    }
                    if (play_myTimer <= 0)
                    
                        played = false;
                        play_myTimer = room_speed*2;
                    }
            }
            else
            {
                speed = 0;
                flight = false;
                sprite_index = party_walk;
            }
        
        
    



////////////////PARENTED PAIRING/////////////////////////
/////////////////PAIRING///////////////////////////////////

if (mouse_check_button_released(mb_left))
{
    

  inst = instance_position(mouse_x, mouse_y, BrainParentObject)
  attackTarget = inst;
 
 //see how close you are to attackTarget
 if distance_to_object(attackTarget)<attackRange
 {
    if (inst.object_index != BrainParentObject && inst.object_index != BatParentObject)
    {   

          
       //end battle
        attacking = false;
        speed = 0;
        path_speed = 0;
        image_index = 0;
          
        //move_towards_point(mouse_x, mouse_y, flyspeed);
        with (attackTarget)
        {
                if attackTarget == other.id
                {
                decision_timer = room_speed+(image_number-image_index)*sprite_get_speed(sprite_index);
                }
        }
        //the party is static
        if(point_distance(x, y, inst.x, inst.y) < 20)
        {
                //sprite_index = global.party_walk;   
                sprite_index =WindBatWalk
        }
     }
    
   }
}


////////////DAMAGE EXCHANGE////////////////
///////////RECEIVE DAMAGE////////////////
    

    hp-= receive_damage;
    receive_damage = 0;



//////////BAT PARENT DAMAGE////////


if (hp <= 0)
{
    instance_create_depth(x,y,-1700, DeadBatObject);
    audio_play_sound(BatDeathSound, 15, false);
    instance_destroy();
}



/////////////DAMAGE EXCHANGE//////////////
//////////DAMAGE OUT TO ENEMY/////////






if distance_to_object(attackTarget) < attackRange
{
    //deal out damage to enemy brain
                
    //total damage to brain
    total_strength = global.bat_strength - global.brain_strength;
    total_defense = global.bat_defense - global.brain_defense;
    total_formula = (global.bat_strength - global.brain_defense)*global.bat_attack
    damage = total_formula*irandom_range(50, 75)/1000
    
    show_debug_message("Damage deal to Brain" + string(damage))       
                    
    //clamping
    if (damage < 0)
    {
        damage = damage * -1;
    }
            
    //deal damage
    with (BrainParentObject)
    {
        receive_damage = damage
    }
            
}
Brain Parent Object

Code:
    hp-= receive_damage;
    receive_damage = 0;
    
    
    ///////////////PAIRING///////////////////
    //////////////////////////////////////////

    attackRange = 50;
    flyspeed = 5;
    floater_myTimer--;

     //if attackTarget is empty
    if (!instance_exists(attackTarget))
    {
        //player presses mouse left
        if (mouse_check_button_released(mb_left))
        {
           //get a bat (was get a bat, now its brain parent
            attackTarget = instance_place(mouse_x, mouse_y, BrainParentObject);
            //show_debug_message("Brain is attacking is : " + string(BatParentObject));
        }
    }

    //make sure thqt attackatarget has a reference
    if instance_exists(attackTarget)
    {
       //When decision_timer is set, count down the timer and clear the attackTarget and attacking
       if decision_timer > 0
       {
          decision_timer--;
          if (decision_timer == 0)
          {
              //brain is no longer attacking
              attackTarget = noone;
              attacking = false;
          }
       }
      
       else if distance_to_object(attackTarget) > attackRange //DECISION TIMER IS 0  AND BRAIN IS NO LONGER ATTCKING
       {//   BRAIN DISTANCE FROM BAT IS > attackRange
           //Far from brain, move towards it
            
            //{
                if attacking == false  //set attacking to false and
                                //move towrds bat
             move_towards_point(attackTarget.x,attackTarget.y, flyspeed);
            //}
          //Note: You could have the decision_timer code under an else-conditional here,
          //which would allow ranged brains to keep attacking until the bat leaves its range
       }
      else //BRAIN DISTANCE TIMER IS 0 AND BRAIN IS CLOSE TO BAT
            //LOCKING IN
            //assign attack target
            //or move towards target
            //or lock in battle
       {
           //LOCK IN BATTLE
        attacking = true;
        speed=0;
        //locked in
        //if global.colliderbat_temp  exists
        //attackTarget is assigned to global.colliderbbat_temp
        if (instance_exists(global.colliderbat_temp))
        {
            attackTarget = global.colliderbat_temp;
            show_debug_message("Brain locked onto attackTarget");
        }
       }
  
    } //end instancfe exits attacktarget

    else
    {
       attacking = false;
       //attackTarget = noone;
       decision_timer = 0;
    
    }
    //////////////////////////////////////////
    ///////////DEMAGE DEALER/////////////////
    //////////////////////////////////////////////
    
    if distance_to_object(attackTarget) < attackRange
{
    //deal out damage to enemy brain
                
    //total damage to brain
    total_strength = global.bat_strength - global.brain_strength;
    total_defense = global.bat_defense - global.brain_defense;
    total_formula = (global.bat_strength - global.brain_defense)*global.bat_attack
    damage = total_formula*irandom_range(50, 75)/1000
    
    show_debug_message("Damage deal to bat" + string(damage))       
                    
    //clamping
    if (damage < 0)
    {
        damage = damage * -1;
    }
    
    ///calculate later
    //global.current_bat_attack_target_damage = damage;
    with (BrainParentObject)
    {
        receive_damage = damage
    }
    //with (other.id)
    //{
//        hp -= damage;
//    }
    /////////////STATUS EFFECTS///////////////
}
    
if (x < 200)        //Enemy Hit the Castle
{
    instance_destroy();
}
    
    //mindbreaker
if (global.mindbreak || global.mindbreaker)
{
    path_start(path30, 15, path_action_reverse, 0);
}



//was hit by a snowball
if (frozen)
{
    path_speed =0;
    speed = 0;
    sprite_index =SnowFrozenEnemy;
    alarm[9] = room_speed;
}

//petrified
if (global.petrification == true)
{
    path_speed = 0;
    speed = 0
    sprite_index = PetrifiedBrain;
}

if (global.freeze_brains)
{
    path_speed = 0;
    speed = 0;
    //sprite_index = BigBrainStill;
    alarm[9] = room_speed;
}

//hit by lightning
was_hit_by_lit = false;


defense = 1;
if (global.defense_boost)
{
    defense = 20;
}




//////////POISON INFLICTED////////////////
/////////////////////////////////////////

/////////////////////////////////
//Poison ZmyTimer
//


if (poisoned)
{
    
    myTimer--;
    if (myTimer <= 0)
    {
        total_strength = strength - other.strength
        total_defense = defense - other.defense
        total_formula = (strength - defense)*attack
        hp_minus = total_formula*irandom_range(200, 400);
        
        hp_minus = damage;
        myTimer = 0;
        floater = instance_create_depth(x+10, y-10, -17000, DamageIndicatorObject);
        floater.text = string(hp_minus);
        
        if (hp <= 0)
        {
            show_debug_message("Dead Brain Ghost and Fading Gem");
            instance_create_depth(x, y, -1100,DeadBrainObject);       
            instance_create_depth(x-150, y-20, -1100, FadingGemObject);
            global.achievement_gold_counter++;
            
            with (other)
            {
                experience += 50
            }
            
            global.achievement_tome_experience += 20;
            instance_destroy();
        }
        myTimer = room_speed;
    }
    under_attack = true;
    took_a_hit = true;
}
    
///
//////////////////////////////////////////////////
///////////////////COLLIDING WITH CASTLE WALL ////////////
//////////////////////////////////////////////////////

//////////////Attack on Castle Wall/////////////////////////





//////////////////////////////////////////////////



if (point_in_rectangle(x-100, y, 156, 100, 600, 1400))
{
    show_debug_message("Wall Collision");

    castle_wall_myTimer--;
    
    if (castle_wall_myTimer <= 0)
    {
    //    hp_minus = irandom_range(40, 150);
        hp_minus = irandom_range(200, 600);
        hp = hp - hp_minus
        global.castle_hp = global.castle_hp - hp_minus;
        path_end();
        
        
        //Trieed 500 unsuccesful. Try ing 600.
        //600 works but spans the whole level
        //trying 650
        if (x < 590 && x>200)  //tried 500 and 600. Tried 550.Tried 590. Tried 580
        {
            show_debug_message("Xdimensions IS " + string(x))
                
            sprite_index = global.brain_party_kill;
        
        
            while (damage_display <= room_speed*10)
            {
                damage_display++;
                floater = instance_create_depth(x,y, -1700, DamageIndicatorObject);           
                floater.text = string(hp_minus);
            }
        }
        
        
         instance_create_depth(x, y-300, -1800, FrankGhostObject);
         instance_destroy()
        //sprite_index = global.brain_party_kill;

        castle_wall_myTimer--;

        number_of_attacks++;

        castle_wall_myTimer = room_speed;
        
        
        show_debug_message("Iterating through step wall myTimer");
    }



}

/////////////////////////////////
/////////////LIGHTNING BAT ATTACK//////////////
/////////////////DEPRECATED//////////////
/////////////////////////////////////////////

//show_debug_message("lit_damage_myTimera: " + string(lit_damage_myTimera));
//show_debug_message("lit_damage_myTimerb: " + string(lit_damage_myTimerb));
//show_debug_message("lit_damage_myTimerc: " + string(lit_damage_myTimerc));
if (global.active) { show_debug_message("Active is true"); }
else { show_debug_message("ACtive is false"); }
if (global.active == true && collision_line(global.litorigin_x, global.litorigin_y, global.lightning_1_x, global.lightning_1_y, ScorpionBrainObject, false, false))
{
    lit_damage_myTimera--;
    show_debug_message("lit_damage_myTimera: " + string(lit_damage_myTimera));
    if (lit_damage_myTimera <= 0)
    {
        
        show_debug_message("Lit myTimer A fire: ");
        total_strength = strength - other.strength
        total_defense = defense - other.defense
        total_formula = (strength - defense)*attack
        hp_minus = total_formula*irandom_range(100, 400);
        
        damage = hp_minus;
        hp = hp - hp_minus;
        floater = instance_create_depth(x, y, -17000, DamageIndicatorObject)   
        floater.text = string(damage)
    
        under_attack = true;
        took_a_hit = true;
        was_hit_by_lit = true;
        lit_damage_myTimera = room_speed*4;
        
    }
}


if (global.active == true && collision_line(global.lightning_1_x, global.lightning_1_y, global.lightning_2_x, global.lightning_2_y, ScorpionBrainObject, false, false))
{
    lit_damage_myTimerb--;

    if (lit_damage_myTimerb <= 0)
    {
        show_debug_message("Lit myTimer B fire: ");
        total_strength = strength - other.strength
        total_defense = defense - other.defense
        total_formula = (strength - defense)*attack
        hp_minus = total_formula*irandom_range(100, 400);
        
        damage = hp_minus;
        hp = hp - hp_minus;
        floater = instance_create_depth(x, y, -17000, DamageIndicatorObject)   
        floater.text = string(damage)
    
        under_attack = true;
        took_a_hit = true;
        was_hit_by_lit = true;
        lit_damage_myTimerb = room_speed*4;
    }
}


if (global.active == true && collision_line(global.lightning_2_x, global.lightning_2_y, global.lightning_3_x, global.lightning_3_y, ScorpionBrainObject, false, false))
{
    lit_damage_myTimerc--;
    if (lit_damage_myTimerc <=0)
    {
        
        show_debug_message("Lit myTimer C fire: ");
                total_strength = strength - other.strength
        total_defense = defense - other.defense
        total_formula = (strength - defense)*attack
        hp_minus = total_formula*irandom_range(100, 400);
        
        damage = hp_minus;
        hp = hp - hp_minus;
        floater = instance_create_depth(x, y, -17000, DamageIndicatorObject)   
        floater.text = string(damage)
    
        under_attack = true;
        was_hit_by_lit = true;
        lit_damage_myTimerc = room_speed*4;
    }

}

//////////////////Lightning Bat KIll////////////////////


if (hp <= 0)
{
    global.achievement_gold_counter++;
    global.achievement_tome_experience += 20;
    
    with (other)
    {
        experience += 30
    }
    
    audio_play_sound(DieingBrainSound, 20, false);
    instance_create_depth(x, y, -1100,DeadBrainObject);       
    instance_create_depth(x-150, y-20, -1100, FadingGemObject);
            
    instance_destroy();
            
}



if (poisoned == true)
{
    hp -= 100
   instance_destroy(PoisonBuffIcon)
   instance_create_depth(x, y-100, -1400, PoisonBuffIcon)
}
 
Specialy Brain (Parent Object)

Code:
attackRange = 50;
flyspeed = 5;
floater_myTimer--;



global.brain_strength = strength
/////////////////DEFENSE//////////////
global.brain_defense = defense

//////////////////ATTACK/////////////////

global.brain_attack = attack

//////////////////////DEXTERITY/////////////
//ability to use a projectile

global.brain_dexterity = dexterity

/////////////////SPEED ///////////

//unaccelerated spaed

global.brain_spd = spd

///////////////INTELLIGENCE////////////////
//strength of projectiles

global.brain_intelligence = intelligence

///////////EXPERIEINCE///////////////

//rolling over experience every time kill something with this bat type

global.brain_experience = experience

///////////////LEVEL///////////////////////////

//experience adds up to a new level for that bat
//this increases stats for that bat type

global.brain_experience_level = experience_level
//////////////////////////////////////////////////

   
   
    ////////////////////////////////////
    //
    // Pairing Code for bat and brain
    // for specialty bads and brains
    //
    ////////////////////////////////////
   
   
   
    //////////////////////////////////////////
    //
    //  Receive damage receiving damage from
    //  brain
    //
    ////////////////////////////////////////
   
   
   
    //hp -= global.current_brain_attack_target_damage
    //global.current_brain_attack_target_damage = 0
    ///////////////PAIRING///////////////////
    hp -= global.current_brain_target_specialty
    global.global.current_brain_target_specialty = 0
    //////////////////////////////////////////


    /////////////////////////////////////////
    //
    // Pairing of Brain and Bat
    //
    //////////////////////////////////////////


    attackRange = 50;
    flyspeed = 5;
    floater_myTimer--;

     //if attackTarget is empty
    if (!instance_exists(attackTarget))
    {
        //player presses mouse left to pair with the brain
        if (mouse_check_button_released(mb_left))
        {
           //get a bat (was get a bat, now its brain parent
            attackTarget = instance_place(mouse_x, mouse_y, SpecialtyBrain);
            //show_debug_message("Brain is attacking is : " + string(BatParentObject));
        }
    }

    //make sure thqt attackatarget has a reference
    if instance_exists(attackTarget)
    {
       //When decision_timer is set, count down the timer and clear the attackTarget and attacking
       if decision_timer > 0
       {
          decision_timer--;
          if (decision_timer == 0)
          {
              //brain is no longer attacking
              attackTarget = noone;
              attacking = false;
          }
       }
     
       else if distance_to_object(attackTarget) > attackRange //DECISION TIMER IS 0  AND BRAIN IS NO LONGER ATTCKING
       {//   BRAIN DISTANCE FROM BAT IS > attackRange
           //Far from brain, move towards it
           
            //{
                if attacking == false  //set attacking to false and
                                //move towrds bat
             move_towards_point(attackTarget.x,attackTarget.y, flyspeed);
            //}
          //Note: You could have the decision_timer code under an else-conditional here,
          //which would allow ranged brains to keep attacking until the bat leaves its range
       }
      else //BRAIN DISTANCE TIMER IS 0 AND BRAIN IS CLOSE TO BAT
            //LOCKING IN
            //assign attack target
            //or move towards target
            //or lock in battle
       {
           //LOCK IN BATTLE
        attacking = true;
        speed=0;
        //locked in
        //if global.colliderbat_temp  exists
        //attackTarget is assigned to global.colliderbbat_temp
        if (instance_exists(global.colliderbat_temp))
        {
            attackTarget = global.colliderbat_temp;
            show_debug_message("Brain locked onto attackTarget");
        }
       }
     
    } //end instancfe exits attacktarget

    else
    {
       attacking = false;
       //attackTarget = noone;
       decision_timer = 0;
   
    }



    //////////////////////////////////////////
    //
    //Deal Damage: Set damage in the global
    //            
    //
    /////////////////////////////////////////
   
    if distance_to_object(attackTarget) < attackRange
    {
    //deal out damage to enemy brain
               
    //total damage to brain
    total_strength = global.bat_strength - global.brain_strength;
    total_defense = global.bat_defense - global.brain_defense;
    total_formula = (global.bat_strength - global.brain_defense)*global.bat_attack
    damage = total_formula*irandom_range(50, 75)/1000
   
    show_debug_message("Damage deal to bat" + string(damage))      
                   
    //clamping
    if (damage < 0)
    {
        damage = damage * -1;
    }
   
   
    ///////////////////////////
    //
    // Deal Damage to Specialty Bat
    //
    ////////////////////////////
    global.current_specialty_bat_target_damage = damage;
   
        loater.text = string(hp_minus);
        global.current_specialty_bat_target_damage = damage
        //hp-= damage;
           
   
        if (hp <= 0)
        {
            with(BatParentObject)
            {
                audio_play_sound(BatDeathSound, 20, false);
                instance_create_depth(x, y, -1100,DeadBatObject);
           
                instance_destroy();
            }

        }
           
    //}
    if (death_sound_flag)
    {
        audio_stop_all();
        audio_play_sound(PlayerDeath, 10, false);
        death_sound_flag = false;
   
    }
    /////////////STATUS EFFECTS///////////////
}
   
if (x < 200)        //Enemy Hit the Castle
{
    instance_destroy();
}
   
    //mindbreaker
if (global.mindbreak || global.mindbreaker)
{
    path_start(path30, 15, path_action_reverse, 0);
}


//was hit by a snowball
if (frozen)
{
    path_speed =0;
    speed = 0;
    sprite_index =SnowFrozenEnemy;

}

//petrified
if (global.petrification == true)
{
    path_speed = 0;
    speed = 0
    sprite_index = PetrifiedBrain;
}

if (global.freeze_brains)
{
    path_speed = 0;
    speed = 0;
    //sprite_index = BigBrainStill;
    alarm[9] = room_speed;
}

//hit by lightning
was_hit_by_lit = false;


defense = 1;
if (global.defense_boost)
{
    defense = 20;
}




//////////POISON INFLICTED////////////////
/////////////////////////////////////////

/////////////////////////////////
//Poison ZmyTimer
//


if (poisoned)
{
   
    myTimer--;
    if (myTimer <= 0)
    {
            total_strength = strength - other.strength
        total_defense = defense - other.defense
total_formula = (strength - defense)*attack
        hp_minus = total_formula*irandom_range(200, 400);
       
        hp_minus = damage;
        myTimer = 0;
        floater = instance_create_depth(x+10, y-10, -17000, DamageIndicatorObject);
        floater.text = string(hp_minus);
       
        if (hp <= 0)
        {
            show_debug_message("Dead Brain Ghost and Fading Gem");
            instance_create_depth(x, y, -1100,DeadBrainObject);      
            instance_create_depth(x-150, y-20, -1100, FadingGemObject);
            global.achievement_gold_counter++;
           
            with (other)
            {
                experience += 50
            }
           
            global.achievement_tome_experience += 20;
            instance_destroy();
        }
        myTimer = room_speed;
    }
    under_attack = true;
    took_a_hit = true;
}
   
///
//////////////////////////////////////////////////
///////////////////COLLIDING WITH CASTLE WALL ////////////
//////////////////////////////////////////////////////

//////////////Attack on Castle Wall/////////////////////////


//global.brain_party_still = ScifiBatSpecialtyBrainStatic;
//global.brain_party_walk = ScifiBatSpecialtyBrainStatic
//global.brain_party_kill = ScifiSpecialtyBrainAttack






if (point_in_rectangle(x-100, y, 156, 100, 600, 1400))
{
    show_debug_message("Wall Collision");

    castle_wall_myTimer--;
   
    if (castle_wall_myTimer <= 0)
    {
    //    hp_minus = irandom_range(40, 150);
        hp_minus = irandom_range(200, 600);
        hp = hp - hp_minus
        global.castle_hp = global.castle_hp - hp_minus;
        path_end();
       
       
        //Trieed 500 unsuccesful. Try ing 600.
        //600 works but spans the whole level
        //trying 650
        if (x < 590 && x>200)  //tried 500 and 600. Tried 550.Tried 590. Tried 580
        {
            show_debug_message("Xdimensions IS " + string(x))
            with (ScorpionBrainObject)
            {
                sprite_index = ScorpionBrainAttack;
            }
       
            with (BigBrainObject)
            {
                sprite_index = BigBrainAttacking
            }
            while (damage_display <= room_speed*10)
            {
                damage_display++;
                floater = instance_create_depth(x,y, -1700, DamageIndicatorObject);          
                floater.text = string(hp_minus);
            }
        }
       
       
         instance_create_depth(x, y-300, -1800, FrankGhostObject);
         instance_destroy()
        //sprite_index = global.brain_party_kill;

        castle_wall_myTimer--;

        number_of_attacks++;

        //if (number_of_attacks > 5)
        //{
        //    instance_destroy();
        //}
   

       
        castle_wall_myTimer = room_speed;
       
       
        //floater = instance_create_depth(x+10, y-10, -17000, DamageIndicatorObject)    ;
        //floater.text = string(hp_minus);  
        show_debug_message("Iterating through step wall myTimer");
    }



}

/////////////////////////////////
/////////////LIGHTNING BAT ATTACK//////////////
/////////////////////////////////////////////

//show_debug_message("lit_damage_myTimera: " + string(lit_damage_myTimera));
//show_debug_message("lit_damage_myTimerb: " + string(lit_damage_myTimerb));
//show_debug_message("lit_damage_myTimerc: " + string(lit_damage_myTimerc));
if (global.active) { show_debug_message("Active is true"); }
else { show_debug_message("ACtive is false"); }
if (global.active == true && collision_line(global.litorigin_x, global.litorigin_y, global.lightning_1_x, global.lightning_1_y, ScorpionBrainObject, false, false))
{
    lit_damage_myTimera--;
    show_debug_message("lit_damage_myTimera: " + string(lit_damage_myTimera));
    if (lit_damage_myTimera <= 0)
    {
       
        show_debug_message("Lit myTimer A fire: ");
        total_strength = strength - other.strength
        total_defense = defense - other.defense
        total_formula = (strength - defense)*attack
        hp_minus = total_formula*irandom_range(100, 400);
       
        damage = hp_minus;
        hp = hp - hp_minus;
        floater = instance_create_depth(x, y, -17000, DamageIndicatorObject)  
        floater.text = string(damage)
   
        under_attack = true;
        took_a_hit = true;
        was_hit_by_lit = true;
        lit_damage_myTimera = room_speed*4;
       
    }
}


if (global.active == true && collision_line(global.lightning_1_x, global.lightning_1_y, global.lightning_2_x, global.lightning_2_y, ScorpionBrainObject, false, false))
{
    lit_damage_myTimerb--;

    if (lit_damage_myTimerb <= 0)
    {
        show_debug_message("Lit myTimer B fire: ");
                total_strength = strength - other.strength
        total_defense = defense - other.defense
        total_formula = (strength - defense)*attack
        hp_minus = total_formula*irandom_range(100, 400);
       
        damage = hp_minus;
        hp = hp - hp_minus;
        floater = instance_create_depth(x, y, -17000, DamageIndicatorObject)  
        floater.text = string(damage)
   
        under_attack = true;
        took_a_hit = true;
        was_hit_by_lit = true;
        lit_damage_myTimerb = room_speed*4;
    }
}


if (global.active == true && collision_line(global.lightning_2_x, global.lightning_2_y, global.lightning_3_x, global.lightning_3_y, ScorpionBrainObject, false, false))
{
    lit_damage_myTimerc--;
    if (lit_damage_myTimerc <=0)
    {
       
        show_debug_message("Lit myTimer C fire: ");
                total_strength = strength - other.strength
        total_defense = defense - other.defense
        total_formula = (strength - defense)*attack
        hp_minus = total_formula*irandom_range(100, 400);
       
        damage = hp_minus;
        hp = hp - hp_minus;
        floater = instance_create_depth(x, y, -17000, DamageIndicatorObject)  
        floater.text = string(damage)
   
        under_attack = true;
        was_hit_by_lit = true;
        lit_damage_myTimerc = room_speed*4;
    }

}

//////////////////Lightning Bat KIll////////////////////


if (hp <= 0)
{
    global.achievement_gold_counter++;
    global.achievement_tome_experience += 20;
   
    with (other)
    {
        experience += 30
    }
   
    audio_play_sound(DieingBrainSound, 20, false);
    instance_create_depth(x, y, -1100,DeadBrainObject);      
    instance_create_depth(x-150, y-20, -1100, FadingGemObject);
           
    instance_destroy();
           
}






if (poisoned == true)
{
    hp -= 100
   instance_destroy(PoisonBuffIcon)
   instance_create_depth(x, y-100, -1400, PoisonBuffIcon)
}
Special Bat

Code:
    ////////////////////////
    //
    // Receiving damage from
    // special bat and reset
    // damage exhange
    //
    ////////////////////////
    
    
    hp -= global.current_specialty_bat_target_damage
    global.current_specialty_bat_target_damage = 0
    ///////////////PAIRING///////////////////
    //////////////////////////////////////////

    attackRange = 50;
    flyspeed = 5;
    floater_myTimer--;

     //if attackTarget is empty
    if (!instance_exists(attackTarget))
    {
        //player presses mouse left
        if (mouse_check_button_released(mb_left))
        {
           //get a bat (was get a bat, now its brain parent
            attackTarget = instance_place(mouse_x, mouse_y, BrainParentObject);
            //show_debug_message("Brain is attacking is : " + string(BatParentObject));
        }
    }

    //make sure thqt attackatarget has a reference
    if instance_exists(attackTarget)
    {
       //When decision_timer is set, count down the timer and clear the attackTarget and attacking
       if decision_timer > 0
       {
          decision_timer--;
          if (decision_timer == 0)
          {
              //brain is no longer attacking
              attackTarget = noone;
              attacking = false;
          }
       }
      
       else if distance_to_object(attackTarget) > attackRange //DECISION TIMER IS 0  AND BRAIN IS NO LONGER ATTCKING
       {//   BRAIN DISTANCE FROM BAT IS > attackRange
           //Far from brain, move towards it
            
            //{
                if attacking == false  //set attacking to false and
                                //move towrds bat
             move_towards_point(attackTarget.x,attackTarget.y, flyspeed);
            //}
          //Note: You could have the decision_timer code under an else-conditional here,
          //which would allow ranged brains to keep attacking until the bat leaves its range
       }
      else //BRAIN DISTANCE TIMER IS 0 AND BRAIN IS CLOSE TO BAT
            //LOCKING IN
            //assign attack target
            //or move towards target
            //or lock in battle
       {
           //LOCK IN BATTLE
        attacking = true;
        speed=0;
        //locked in
        //if global.colliderbat_temp  exists
        //attackTarget is assigned to global.colliderbbat_temp
        if (instance_exists(global.colliderbat_temp))
        {
            attackTarget = global.colliderbat_temp;
            show_debug_message("Brain locked onto attackTarget");
        }
       }
      
    } //end instancfe exits attacktarget

    else
    {
       attacking = false;
       //attackTarget = noone;
       decision_timer = 0;
    
    }
    ////////////////////////////////////
    //
    //  Deal Damage to Special Brain
    //
    /////////////////////////////////////
    
    if distance_to_object(attackTarget) < attackRange
{
    //deal out damage to enemy brain
                
    //total damage to brain
    total_strength = global.bat_strength - global.brain_strength;
    total_defense = global.bat_defense - global.brain_defense;
    total_formula = (global.bat_strength - global.brain_defense)*global.bat_attack
    damage = total_formula*irandom_range(50, 75)/1000
    
    show_debug_message("Damage deal to bat" + string(damage))       
                    
    //clamping
    if (damage < 0)
    {
        damage = damage * -1;
    }
    
    
    /////////////////////////
    //
    // Set damage to attack
    // specialty brain
    //
    ///////////////////////
    
    global.current_brain_target_specialty = damage;
    //with(other.id)
    {
        hp -= damage
        floater = instance_create_depth(x+10, y-10, -17000, MuscleDamageIndicatorObject);
        floater.text = string(hp_minus);
    }
    /////////////STATUS EFFECTS///////////////
}

//////////////////////////////
//
// Castle collision
//
//
//////////////////////////////

if (x < 200)        //Enemy Hit the Castle
{
    instance_destroy();
}
    
    //mindbreaker
if (global.mindbreak || global.mindbreaker)
{
    path_start(path30, 15, path_action_reverse, 0);
}



//was hit by a snowball
if (frozen)
{
    path_speed =0;
    speed = 0;
    sprite_index =SnowFrozenEnemy;
    alarm[9] = room_speed;
}

//petrified
if (global.petrification == true)
{
    path_speed = 0;
    speed = 0
    sprite_index = PetrifiedBrain;
}

if (global.freeze_brains)
{
    path_speed = 0;
    speed = 0;
    //sprite_index = BigBrainStill;
    alarm[9] = room_speed;
}

//hit by lightning
was_hit_by_lit = false;


defense = 1;
if (global.defense_boost)
{
    defense = 20;
}




//////////POISON INFLICTED////////////////
/////////////////////////////////////////

/////////////////////////////////
//Poison ZmyTimer
//


if (poisoned)
{
    
    myTimer--;
    if (myTimer <= 0)
    {
            total_strength = strength - other.strength
        total_defense = defense - other.defense
total_formula = (strength - defense)*attack
        hp_minus = total_formula*irandom_range(200, 400);
        
        hp_minus = damage;
        myTimer = 0;
        floater = instance_create_depth(x+10, y-10, -17000, DamageIndicatorObject);
        floater.text = string(hp_minus);
        
        if (hp <= 0)
        {
            show_debug_message("Dead Brain Ghost and Fading Gem");
            instance_create_depth(x, y, -1100,DeadBrainObject);       
            instance_create_depth(x-150, y-20, -1100, FadingGemObject);
            global.achievement_gold_counter++;
            
            with (other)
            {
                experience += 50
            }
            
            global.achievement_tome_experience += 20;
            instance_destroy();
        }
        myTimer = room_speed;
    }
    under_attack = true;
    took_a_hit = true;
}
    
///
//////////////////////////////////////////////////
///////////////////COLLIDING WITH CASTLE WALL ////////////
//////////////////////////////////////////////////////

//////////////Attack on Castle Wall/////////////////////////


//global.brain_party_still = ScifiBatSpecialtyBrainStatic;
//global.brain_party_walk = ScifiBatSpecialtyBrainStatic
//global.brain_party_kill = ScifiSpecialtyBrainAttack



attackRange = 50;
flyspeed = 5;
floater_myTimer--;


/*
global.brain_strength = strength
/////////////////DEFENSE//////////////
global.brain_defense = defense

//////////////////ATTACK/////////////////

global.brain_attack = attack

//////////////////////DEXTERITY/////////////
//ability to use a projectile

global.brain_dexterity = dexterity

/////////////////SPEED ///////////

//unaccelerated spaed

global.brain_spd = spd

///////////////INTELLIGENCE////////////////
//strength of projectiles

global.brain_intelligence = intelligence

///////////EXPERIEINCE///////////////

//rolling over experience every time kill something with this bat type

global.brain_experience = experience

///////////////LEVEL///////////////////////////
*
//experience adds up to a new level for that bat
//this increases stats for that bat type
*/
global.brain_experience_level = experience_level


///////////////damage/////////////////////
show_debug_message("DAMAGE" + string(global.current_brain_attack_target_damage));
if (global.current_brain_attack_target_damage > 0)
{
//direct damage works
//global.current_brain_attack_target_damage is 0
    hp -= 50;
    //hp -= global.current_brain_attack_target_damage;
    //global.current_brain_attack_target_damage = 0;     //reset damage
}




/////////////STRENGTH//////////////


    

//////////////////////////////////////////////////



if (point_in_rectangle(x-100, y, 156, 100, 600, 1400))
{
    show_debug_message("Wall Collision");

    castle_wall_myTimer--;
    
    if (castle_wall_myTimer <= 0)
    {
    //    hp_minus = irandom_range(40, 150);
        hp_minus = irandom_range(200, 600);
        hp = hp - hp_minus
        global.castle_hp = global.castle_hp - hp_minus;
        path_end();
        
        
        //Trieed 500 unsuccesful. Try ing 600.
        //600 works but spans the whole level
        //trying 650
        if (x < 590 && x>200)  //tried 500 and 600. Tried 550.Tried 590. Tried 580
        {
            show_debug_message("Xdimensions IS " + string(x))
            with (ScorpionBrainObject)
            {
                sprite_index = ScorpionBrainAttack;
            }
        
            with (BigBrainObject)
            {
                sprite_index = BigBrainAttacking
            }
            while (damage_display <= room_speed*10)
            {
                damage_display++;
                floater = instance_create_depth(x,y, -1700, DamageIndicatorObject);           
                floater.text = string(hp_minus);
            }
        }
        
        
         instance_create_depth(x, y-300, -1800, FrankGhostObject);
         instance_destroy()
        //sprite_index = global.brain_party_kill;

        castle_wall_myTimer--;

        number_of_attacks++;

        //if (number_of_attacks > 5)
        //{
        //    instance_destroy();
        //}
    

        
        castle_wall_myTimer = room_speed;
        
        
        //floater = instance_create_depth(x+10, y-10, -17000, DamageIndicatorObject)    ;
        //floater.text = string(hp_minus);   
        show_debug_message("Iterating through step wall myTimer");
    }



}

/////////////////////////////////
/////////////LIGHTNING BAT ATTACK//////////////
/////////////////////////////////////////////

//show_debug_message("lit_damage_myTimera: " + string(lit_damage_myTimera));
//show_debug_message("lit_damage_myTimerb: " + string(lit_damage_myTimerb));
//show_debug_message("lit_damage_myTimerc: " + string(lit_damage_myTimerc));
if (global.active) { show_debug_message("Active is true"); }
else { show_debug_message("ACtive is false"); }
if (global.active == true && collision_line(global.litorigin_x, global.litorigin_y, global.lightning_1_x, global.lightning_1_y, ScorpionBrainObject, false, false))
{
    lit_damage_myTimera--;
    show_debug_message("lit_damage_myTimera: " + string(lit_damage_myTimera));
    if (lit_damage_myTimera <= 0)
    {
        
        show_debug_message("Lit myTimer A fire: ");
        total_strength = strength - other.strength
        total_defense = defense - other.defense
        total_formula = (strength - defense)*attack
        hp_minus = total_formula*irandom_range(100, 400);
        
        damage = hp_minus;
        hp = hp - hp_minus;
        floater = instance_create_depth(x, y, -17000, DamageIndicatorObject)   
        floater.text = string(damage)
    
        under_attack = true;
        took_a_hit = true;
        was_hit_by_lit = true;
        lit_damage_myTimera = room_speed*4;
        
    }
}


if (global.active == true && collision_line(global.lightning_1_x, global.lightning_1_y, global.lightning_2_x, global.lightning_2_y, ScorpionBrainObject, false, false))
{
    lit_damage_myTimerb--;

    if (lit_damage_myTimerb <= 0)
    {
        show_debug_message("Lit myTimer B fire: ");
                total_strength = strength - other.strength
        total_defense = defense - other.defense
        total_formula = (strength - defense)*attack
        hp_minus = total_formula*irandom_range(100, 400);
        
        damage = hp_minus;
        hp = hp - hp_minus;
        floater = instance_create_depth(x, y, -17000, DamageIndicatorObject)   
        floater.text = string(damage)
    
        under_attack = true;
        took_a_hit = true;
        was_hit_by_lit = true;
        lit_damage_myTimerb = room_speed*4;
    }
}


if (global.active == true && collision_line(global.lightning_2_x, global.lightning_2_y, global.lightning_3_x, global.lightning_3_y, ScorpionBrainObject, false, false))
{
    lit_damage_myTimerc--;
    if (lit_damage_myTimerc <=0)
    {
        
        show_debug_message("Lit myTimer C fire: ");
                total_strength = strength - other.strength
        total_defense = defense - other.defense
        total_formula = (strength - defense)*attack
        hp_minus = total_formula*irandom_range(100, 400);
        
        damage = hp_minus;
        hp = hp - hp_minus;
        floater = instance_create_depth(x, y, -17000, DamageIndicatorObject)   
        floater.text = string(damage)
    
        under_attack = true;
        was_hit_by_lit = true;
        lit_damage_myTimerc = room_speed*4;
    }

}

//////////////////Lightning Bat KIll////////////////////


if (hp <= 0)
{
    global.achievement_gold_counter++;
    global.achievement_tome_experience += 20;
    
    with (other)
    {
        experience += 30
    }
    
    audio_play_sound(DieingBrainSound, 20, false);
    instance_create_depth(x, y, -1100,DeadBrainObject);       
    instance_create_depth(x-150, y-20, -1100, FadingGemObject);
            
    instance_destroy();
            
}


////////////////////////////////////////////
/////////////PATH ASSIGNMENTS//////////////////
////////////////////////////////////////////
/*
path_change--;
//randomly change paths
//mppath appends to my_path
if (path_change <= 0 && !global.in_battle)
{
    path_change = room_speed*4;


    random_num = random_range(0, 10);


    if (random_num <= 10 && random_num > 5)
    {
         path_append(path37,  DesertBrain);

    }

    else if (random_num <= 5 && random_num > 3)
    {
        path_append(path37,  ForestPath);
    }

    else if (random_num <= 3 && random_num >= 2)
    {
         path_append(path37, path6);
    }
    else
    {
        path_append(path37,  path7);
    }
}*/



if (poisoned == true)
{
    hp -= 100
   instance_destroy(PoisonBuffIcon)
   instance_create_depth(x, y-100, -1400, PoisonBuffIcon)
}

event_inherited();
 
Last edited:
@chamaeleon. I honestly not trying to batttle or say whose project is bigger or more complex/complicated or better, I'm simply refuting your statement. My project is 2 GB compiled. Now there is a decent amount that is artwork, but not much more than the typical in a game. When we're done well have to trade projects. I think that would be fun.
 

Nidoking

Member
When two of these things collide, it looks like you're creating room_speed * 10 individual instances of this DamageIndicatorObject. That's probably the problem.
 

chamaeleon

Member
@chamaeleon. I honestly not trying to batttle or say whose project is bigger or more complex/complicated or better, I'm simply refuting your statement. My project is 2 GB compiled. Now there is a decent amount that is artwork, but not much more than the typical in a game. When we're done well have to trade projects. I think that would be fun.
Let me be perfectly clear, I have no doubt whatsoever that what you have worked on is massively much bigger than anything I have when it comes to GMS. But it's entirely beside the point. Regardless of size of a project, debugging methods remain the same: Use the debugger, or create traces of execution using show_debug_message() or logging to a file for reading and analysis after a run of the program. You need to generate reproducible data points that allows logical problem solving.
 
Let me be perfectly clear, I have no doubt whatsoever that what you have worked on is massively much bigger than anything I have when it comes to GMS. But it's entirely beside the point. Regardless of size of a project, debugging methods remain the same: Use the debugger, or create traces of execution using show_debug_message() or logging to a file for reading and analysis after a run of the program. You need to generate reproducible data points that allows logical problem solving.
When did this come to a lesson on debugging? I was just joking around, We all know how to program. (well most of us) My method: debug statement, either debug or comment out code or both. Look the manual. Look for help. See if you can replicate that problem,
 

chamaeleon

Member
Out of curiosity, because it's not entirely well spelled out in the above code blocks, and I can't determine if each of the code blocks is in only one event or in multiple events, is any of the code in them in collision events or is it all step event code?
 
Top