• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

[SOLVED] Not set Before reading it

C

chamo55

Guest
Hello , i have a problem it sometimes works and sometimes doesnt work.How can i fix it?

Code:
___________________________________________
############################################################################################
FATAL ERROR in
action number 1
of Alarm Event for alarm 0
for object obj_Merkez:

Variable obj_Dot.i(100002, -2147483648) not set before reading it.
 at gml_Object_obj_Merkez_ObjAlarm0_1 (line 8) -             other.dotsA[i] = random(360);
############################################################################################

create

Code:
alarm[0] = 30*2;
for(i=0;i<100;i++)dots[i] = 0;
for(i=0;i<100;i++)dotsA[i] = 0;
targetA = 0;
DotSayi = 0;
target=0;
X =x;
Y =y;
Alarm 0

Code:
DotSayi = global.dot;
random_set_seed(current_second);
for(i=0;i<DotSayi;i++){
    dotsA[i] = random(360);
    dots[i] = instance_create(x+225*cos(dotsA[i]),y+255*sin(dotsA[i]),obj_Dot);
    with(dots[i]){
        while(place_meeting(x, y, obj_Dot)){
            other.dotsA[i] = random(360);
            x = other.x+225*cos(other.dotsA[i]);
            y = other.y+255*sin(other.dotsA[i]);
        }
    }
}

targetA = random(360);
target = instance_create(x+225*cos(targetA),y+255*sin(targetA),obj_Target);

with(target){
    while(place_meeting(x,y, obj_Dot)){
        other.targetA = random(360);
        x = other.x+225*cos(other.targetA);
        y = other.y+255*sin(other.targetA);
    }
}
step

Code:
if(target){
    targetA+=.1;
    with(target){
        x = other.x+225*cos(other.targetA);
        y = other.y+255*sin(other.targetA);
    }
}
press A-key (when press A,obj_dot and obj_target destroy himself

Code:
alarm[0]=10;
 
Last edited by a moderator:

sylvain_l

Member
just define var i = 0; to get i as a local var (scoped to scipt, instead of using an instance var, that can be problematic when you change scope using the with() keyword.
Code:
var i  = 0; //ensure variable i is script scoped
DotSayi = global.dot;
random_set_seed(current_second);
for(i=0;i<DotSayi;i++){
    dotsA[i] = random(360);
    dots[i] = instance_create(x+225*cos(dotsA[i]),y+255*sin(dotsA[i]),obj_Dot);
    with(dots[i]){
        while(place_meeting(x, y, obj_Dot)){
            other.dotsA[i] = random(360);
            x = other.x+225*cos(other.dotsA[i]);
            y = other.y+255*sin(other.dotsA[i]);
        }
    }
}

targetA = random(360);
target = instance_create(x+225*cos(targetA),y+255*sin(targetA),obj_Target);

with(target){
    while(place_meeting(x,y, obj_Dot)){
        other.targetA = random(360);
        x = other.x+225*cos(other.targetA);
        y = other.y+255*sin(other.targetA);
    }
}
p.s.
and it work sometime I assume because as you use i as an instance variable in the create, sound most of your object have an i defined (but you must have some bug going on here cause the i used isn't the one you think^^)
 
Top