A question about event_inherited

Status
Not open for further replies.
This might be a bit off topic but I have a parent brain that is a parent for all. Its not physically in the game screen. . As soon as the desert brain spawns, it says:

GML:
___________________________________________
############################################################################################
FATAL ERROR in
action number 1
of  Step Event0
for object SpecialtyBrain:

global variable name 'current_brain_specialty_target' index (101260) not set before reading it.
 at gml_Object_SpecialtyBrain_Step_0 (line 4) -        hp -= global.current_brain_specialty_target
############################################################################################
--------------------------------------------------------------------------------------------
stack frame is
gml_Object_SpecialtyBrain_Step_0 (line 4)
called from - gml_Object_DesertSpecialtyBrain_Step_0 (line 67) - event_inherited();
Now,
hp -= global.current_brain_specialty_target
is initated the create event already.

This is a snippet:

Code:
alarm[4] = room_speed/4;

    
    hp -= global.current_brain_attack_target_damage
    global.current_brain_attack_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;
    
    }
I know its long and complicated, but it is what it is.
 

Nidoking

Member
Which Create event is global.current_brain_specialty_target initialized in, meaning the Create event of which object? Keep in mind that if it's defined in a parent of SpecialtyBrain and SpecialtyBrain has its own Create event defined, it needs to call event_inherited to perform the parent object's event.
 
RIght. Its defined in the parent of SpecialtyBrain, so I need to call event_inherited. Not quite shure where in the event to call event_inherited though. GMS OO is weird.
 

Nidoking

Member
You just call it at whichever point you want the steps that are in the parent event to happen. If it's just defining some variables, then it doesn't matter when. Your usual flow would be:
  • Set up any variables in the child that the parent would rely on (for instance, if the parent object defines something based on which type of child it is)
  • Call event_inherited
  • Set up any remaining variables and scripts
In most cases, calling event_inherited first is the simplest approach.
 
What about this error? Mind you, these errors showed up all at once;

GML:
RUINS) Variable RuinsFrankObject.dexterity(100891, -2147483648) not set before reading it.
 at gml_Object_LightningBatObject_Collision_f05aa3ba_df78_4f53_9ea3_4767ca239c56 (line 5) -               hp_minus = strength*dexterity*intelligence*irandom_range(20, 50)/500;
############################################################################################
And again, dexterity is declared in the create event but it still GMS says the opposite
 

chamaeleon

Member
What about this error? Mind you, these errors showed up all at once;

GML:
RUINS) Variable RuinsFrankObject.dexterity(100891, -2147483648) not set before reading it.
at gml_Object_LightningBatObject_Collision_f05aa3ba_df78_4f53_9ea3_4767ca239c56 (line 5) -               hp_minus = strength*dexterity*intelligence*irandom_range(20, 50)/500;
############################################################################################
And again, dexterity is declared in the create event but it still GMS says the opposite
But has the code that sets it run before your try to use it? How have you verified this?
 

Nidoking

Member
You need to pay attention to the object names in the error message. This line looks like it's in a LightningBatObject Collision event, but the instance it's trying to read dexterity from is a RuinsFrankObject. That might mean you're inside a with block and missing other.dexterity (for example).
 
You need to pay attention to the object names in the error message. This line looks like it's in a LightningBatObject Collision event, but the instance it's trying to read dexterity from is a RuinsFrankObject. That might mean you're inside a with block and missing other.dexterity (for example).
I am. The lightningbatobject is colliding with the RuinsFrankObject. Its trying to read dexterity to calculate damage. But....it says there isn't dexterity when there actually is there. dexterity is declared in the create event.
 

chamaeleon

Member
dexterity is declared in the create event.
... in which object? LightningBatObject or RuinsFrankObject? And is it the same instance that is running code as the one that declared it as an instance variable for itself, something that changes when you're inside a with statement? GMS is not lying to you. It is running code for an instance that does not have dexterity set.
 

Nidoking

Member
I am. The lightningbatobject is colliding with the RuinsFrankObject. Its trying to read dexterity to calculate damage. But....it says there isn't dexterity when there actually is there. dexterity is declared in the create event.
Unfortunately, this comment isn't making it clear to me which object has the dexterity value. The program is looking for it in the RuinsFrankObject. If dexterity is defined in the LightningBatObject, then it's not being found because the scope is incorrect. When you say "the create event", please specify which object's create event.
 
... in which object? LightningBatObject or RuinsFrankObject? And is it the same instance that is running code as the one that declared it as an instance variable for itself, something that changes when you're inside a with statement? GMS is not lying to you. It is running code for an instance that does not have dexterity set.
In both. Both the bat and frank have dexterity attributes.

GML:
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;
        
    }
 

Nidoking

Member
I think you may have pasted the wrong bit of code there. But here's the checklist I would use:
First, is the dexterity variable set in the actual RuinsFrankObject, or in a parent? If it's in a parent, remember to use event_inherited. If that parent also has a parent, you may need to run event_inherited inside that too.
Second, I would make sure that the event with the variable definition is being run before this one. I know you said it was in a Create event, but there are edge cases where that doesn't run, such as if you use instance_change with a false parameter to tell Game Maker not to run the destroy and create events. I've run into that problem a few times myself. You can verify this by using either debug statements or breakpoints at the definition of the variable - I use breakpoints, so that I can get the instance id of each instance that defines the variable. Then, when the game hits the line where it's crashing, you can check the instance id that's looking for dexterity and see whether it's one of the ones that defined the variable.
Third, check the spelling. If you define it as detxerity, for example, that won't match the check.
I really can't think of any other things that could be the problem, but if I do, I'll add them once you've checked these things.
 

chamaeleon

Member
In both. Both the bat and frank have dexterity attributes.

GML:
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;
       
    }
Not in that code they don't, if that is supposed to be the initialization code that ensure dexterity is set before you use it.
 

chamaeleon

Member
Think of a pen and paper game. Both characters have dexterity. Referring to the code I posted, the dexterity are in their own object.
Referring to that code snippet helps not one bit since the word dexterity does not occur in the posted snippet. It matters not one bit what you may want something to be or what mental picture you may have of it, if your code does not implement it that way in a correct fashion, by declaring and assigning a value to an instance variable before you use it. If GMS says an instance does not have it, it does not have it.
 
The other issue I am having with event_inherited() is this error:


___________________________________________
############################################################################################
FATAL ERROR in
action number 1
of Step Event0
for object SpecialtyBrain:
global variable name 'current_brain_specialty_target' index (101260) not set before reading it.
at gml_Object_SpecialtyBrain_Step_0 (line 4) - hp -= global.current_brain_specialty_target
############################################################################################
--------------------------------------------------------------------------------------------
stack frame is
gml_Object_SpecialtyBrain_Step_0 (line 4)
called from - gml_Object_SnowSpecialty_Step_0 (line 51) - event_inherited()
For this piece of code (I think)
GML:
___________________________________________
############################################################################################
FATAL ERROR in
action number 1
of  Step Event0
for object SpecialtyBrain:

global variable name 'current_brain_specialty_target' index (101260) not set before reading it.
 at gml_Object_SpecialtyBrain_Step_0 (line 4) -        hp -= global.current_brain_specialty_target
############################################################################################
--------------------------------------------------------------------------------------------
stack frame is
gml_Object_SpecialtyBrain_Step_0 (line 4)
called from - gml_Object_SnowSpecialty_Step_0 (line 51) - event_inherited()
    //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
So, I'm learning. :)
 

chamaeleon

Member
The other issue I am having with event_inherited() is this error:




For this piece of code (I think)
GML:
___________________________________________
############################################################################################
FATAL ERROR in
action number 1
of  Step Event0
for object SpecialtyBrain:

global variable name 'current_brain_specialty_target' index (101260) not set before reading it.
at gml_Object_SpecialtyBrain_Step_0 (line 4) -        hp -= global.current_brain_specialty_target
############################################################################################
--------------------------------------------------------------------------------------------
stack frame is
gml_Object_SpecialtyBrain_Step_0 (line 4)
called from - gml_Object_SnowSpecialty_Step_0 (line 51) - event_inherited()
    //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
So, I'm learning. :)
Do you have any code anywhere else in your project that sets global.current_brain_specialty_target? Your posted code only shows the reset to 0 which occurs after the use of it.
 

Nidoking

Member
Could you maybe just post all of the Create events here, including the name of each object with it? All parents, all children, everything relating to the errors you're seeing.
 
Could you maybe just post all of the Create events here, including the name of each object with it? All parents, all children, everything relating to the errors you're seeing.
I"m not in the frickin mood. I'm having major problems with my game, GMS keeps on losing my resources. @TsukaYuriko if you are there? If you are, can you please wipe Nidokin,s previous post. It violates the forums policy.
 

chamaeleon

Member
I'm having major problems with my game
You are not providing enough context to give an exact answer, only guesses. When GMS says an instance variable is not defined, it isn't. Either because no code exists that sets it, or a piece of code didn't run before another piece of code, or because you declared it but not on the instance you wanted it declared on, or you are attempting to read it from the wrong instance after having set it on the "correct" instance.
 

Nidoking

Member
I don't see any forum policy that I would be violating by asking for the information necessary to solve the problem you're describing. However, quoted from the Programming Forum Guidelines:
Share as much relevant information as possible.
Only relevant. It would save a lot of time which would otherwise be wasted in other members asking you to do the same. Better to do that in the first place.
Cite where the code comes from.
Context matters when it comes to coding. Whenever you post a code fragment, explicity state what event / object / script it has been put in.
I have requested that you do this. If you don't, I don't think anyone can help you.
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
I"m not in the frickin mood. I'm having major problems with my game, GMS keeps on losing my resources. @TsukaYuriko if you are there? If you are, can you please wipe Nidokin,s previous post. It violates the forums policy.
Okay, that's quite enough of that thank you very much. First, there is NOTHING in his post that breaks the forum rules, and second, you really shouldn't name drop a moderator to try and interfere in the normal course of a topic. Use the REPORT button if you have an issue with someones reply.

Look, I understand this is frustrating for you, but you have to understand that everyone here is just trying to help and get you a solution to your issue. Treating them like this isn't going to get you anywhere, and it just means future topics you make will get less answers. So, deep breaths, calm down and be thankful that people are at least trying to help you. ;)

That said, this topic is pretty massive and @Nidoking has a point... It might be best if you post EVERYTHING in the most concise and linear way possible so that we can all take a fresh look at the issue.
 
But has the code that sets it run before your try to use it? How have you verified this?
Yes. I have a whole bunch of errors now .I've taken care of the errors from before.
A bunch of specialty brains won't spawn.

(DESERT) Doesn't spawn the Desert Specialty Brain

(RUINS) Brain spawn no error
(JUNGLE) Bat gets locked up with the Jungle SpecialtyBrain

(SWAMP) Doesn't damage to swamp brain

(STORM) Doesn't spawned a Storm Specialty Brain


(SKY) Sky Brain Spawned but doesn't get locked up and stuck
 
I don't see any forum policy that I would be violating by asking for the information necessary to solve the problem you're describing. However, quoted from the Programming Forum Guidelines:


This was a misunderstand. Disregard it.

I have requested that you do this. If you don't, I don't think anyone can help you.
I"m not in the frickin mood. I'm having major problems with my game, GMS keeps on losing my resources. @TsukaYuriko if you are there? If you are, can you please wipe Nidokin,s previous post. It violates the forums policy.
 
Status
Not open for further replies.
Top