PreCreate error. Variable not set before reading it. Help!

sammaster9

Member
I'm getting an odd 'Variable not set before reading it' error in the PreCreate event for an object. See attached image for details. Months ago, I changed the variable definition for scoreImage from 'spr_t1_spider_run' to 'spr_t2_rider_mine_projectile'. However, it appears as if the value is still 'spr_t1_spider_run' in the preCreate event. You can see this in the error. The file in question 'spr_t1_spider_run' was deleted months ago, and no results are returned when searching for it with ctrl+shift+f.

I do not know how to fix this. I've tried updating the scoreImage definition again, as well as running a Build > Clean.
To my knowledge, the preCreate event is not something I can edit. Does anyone know how to solve this?
Any insight would be greatly appreciated. Thank you!

EDIT: To clarify, this error occurs as soon as the obj_t2_rider_mine object is spawned into the room.

Windows. IDE v2.3.7.603 Runtime v2.3.7.474

precreateError.png
 
Last edited:

sammaster9

Member
Check whether any instances of this object that are placed in a room override the default value.
Thank you for the reply!

I checked the layer properties in all of the rooms where this occurs (the multiplayer maps). I saw no instances of this object present. To clarify, this error occurs as soon as the object is spawned into the room. I will update original post to have this clarification.
 

trip

Member
post create code for both obj_t2_rided_mine and his parent obj_t2_ground_unit.
post variable definitions for parent obj_t2_ground_unit ---- I think here is the error. because you can't find variable (with ctrl+shift+f) in variable definition. It must by placed in creation code for finding and better debuging.

correct example without error
//cration event
spr_t1_spider_run = sprite_spider
scoreImage = spr_t1_spider_run

and with the error
//missing variable declaration
scoreImage = spr_t1_spider_run
 
Last edited:

sammaster9

Member
post create code for both obj_t2_rided_mine and his parent obj_t2_ground_unit.
post variable definitions for parent obj_t2_ground_unit ---- I think here is the error. because you can't find variable (with ctrl+shift+f) in variable definition. It must by placed in creation code for finding and better debuging.

correct example without error
//cration event
spr_t1_spider_run = sprite_spider
scoreImage = spr_t1_spider_run

and with the error
//missing variable declaration
scoreImage = spr_t1_spider_run
Here is the create event for obj_t2_rider_mine
GML:
event_inherited();

        myProjectile = obj_t2_rider_mine_projectile;
        objFriendlyMech = obj_t2_mech;
        objEnemyMech = obj_t1_mech;
        myLegSprite = spr_t2_rider_mine_leg;
        myLeapingSprite = spr_t2_rider_mine_leaping;
        friendlyMines = obj_t2_rider_mine_projectile;
    
    legHeights = [1.5, 3, 5, 6, 6.5, 7, 7, 7, 7, 6.5, 6, 5.5, 5, 4, 3, 2, 1];
    legBodyAnchors = [[-7,-7], [7,-7], [-7,3], [7,3]];
    legAngles = [0, 0, 0, 0];
    baseFeetPositionOffsets = [[-10,-8], [10,-8], [-10,8], [10,8]];
    feetPositions = [[x-10,y-8], [x+10,y-8], [x-10,y+8], [x+10,y+8]];
    feetGoalPositions = [[x-10,y-8], [x+10,y-8], [x-10,y+8], [x+10,y+8]];
    legFrame = 0;
    legGroupToMove = 0;
    legGroup = [[0,3],[1,2]]; //opposite legs are grouped
    canRide = true;
    has_ability = false;
    has_ability_taken_script = false;

    //personal_space is for speading units out when they're overlapping
    personal_space = 24;

    //set up animation vars and matrices
    x_frame_size = 24;
    y_frame_size = 24;
    x_frame = 0;
    y_frame = 0;

Here is the creation code for the parent object obj_t2_ground_unit

Code:
myAttackSound = noone;
hp = max_health;
has_ability = true;
myAbility = [spr_mech_spreadshot, scr_mech_spreadshot, spr_spreadshot_pickup];
myAbilitySpriteRelative = true;
myAbilitySpriteOffset = 30;
myAbilityPosition = [0,0];
dir = 0;
speed = 0;
can_attack = true;
myAbilityTakenScript = noone;
has_ability_taken_script = false;
inGrabRangeThisFrame = false;
closestAllyToMech = false;
closestAllyToMechPreviously = false;
i💩💩💩💩 = false;
didTelegraph = false;
doesTelegraph = true;
attackStuns = false;
attackStunDuration = 0;
stunType = false;
attackKnockBackDistance = 0;
fall_y_offset = - 50;
showAbilityDot = 0;

recentHealing = 0;
recentDamage = 0;
framesSinceHealing = 50;
framesSinceDamage = 50;
framesSinceAttacking = 50;
framesSinceWindup = 50;
recentWindupXFrame = 0;
recentDamageLocation = [x,y];
pickupScale = 0.8;
scr_unit_become_stunned(spawnDuration, "summoningSickness");

reverseWaypointDirection = false;
Thanks for the suggestion of looking at the variable definitions of the parent object, that's where I thought it could've been as well.
The parent object has scoreImage = noone in its variable definitions. This is overridden by the child object.
 

sammaster9

Member
Update: If I create a new sprite and name it spr_t1_spider_run it makes it so the game no longer errors. The object does not use the new sprite, but the existence of that sprite causes the game to not error when the object is created. This means the problem is still unsolved, but at least the error will no longer prevent me from testing.

I appreciate the responses from everyone, and if anyone would like to share another idea, I'd love to hear it.

Thanks!
 

trip

Member
I think all is correct.
You can try copy project (just to be sure), remove score_image from parent variable definition. Run game and test that the error is repaired. When yes, you can try to place variable sprite_image into parent variable definition again.
 
Top