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

Q&A Spawn Camper
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

Q&A Spawn Camper
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

Q&A Spawn Camper
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.
 
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;
        }
     }
    
   }
}
 
Top