• 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 create_instance_layer doubles the amount of objects

Y

YourGrandpa

Guest
Hey Gamemaker community,
as the title says i struggle with the create_instance_layer, i made some kind of loop with a counter but as soon one runs trough is complete it doubles the amount of objects created by it which wasnt intended.
Really tried to solve this on my own but i cant get my head around it just doubles. So i hope you guys and girls can help out.

// create event
xRandom = irandom_range(1,10)*32;
yRandom = irandom_range(1,10)*32;
counter = 0 ;

// step event
if(counter == 160){
// creating block at random position
instance_create_layer(xRandom,yRandom,"Instances",objGround);

counter = 0;
} else {
counter++;
show_debug_message(counter);
}



debug output
Entering main loop.
**********************************.
1
2
3
4
5
6
7
8
9
10
11
.....

1
1
2
2
3
3
4
4
5
5
6
6
7
7
8
8
9
9
10
10
...
 
You haven't specified what object this code belongs to, but if I had to guess, it's within objGround, which then would make perfect sense.
 
Y

YourGrandpa

Guest
Oh sorry forgot that. So i made an object called objLevelGenerator and objGround is a child object.
 

FrostyCat

Redemption Seeker
Child objects copy code from their parent unless otherwise overridden. You should NOT make an object a child of another object just because it is referenced by the other object. Inheritance is an "A is a B" relationship, not an "A talks about B" relationship.
 
Y

YourGrandpa

Guest
Thanks a lot for pointing this out, it makes sense now ... man i feel so dumb now.
 
Top