Infinite instances?!?

S

Skivenous

Guest
I have an optimization issue: I'm making a game that builds bricks across a line, and when the line is full it destroys them. But when testing the game, I get 10 or so lines in and the game slows massively. In debug it shows that tons of instances of the brick object are still in the game, even though they should be deleted. I also have code that should be preventing bricks to be placed if one is there already. Help! I have a lot of code and am not sure which to post, so I'll just show the delete row code: (ignore syntax I'm typing this on a phone)

xx=x;
yy=y;
row_full = true;

while (place_meeting (xx-32, y, objwall) ==false) {
Xx-=32;
If (place_meeting(xx,y,objbricks)==0){
Row_full=false;
Break;
}}

while (place_meeting (xx+32, y, objwall) ==false) {
Xx+=32;
If (place_meeting(xx,y,objbricks)==0){
Row_full=false;
Break;
}}

If (row_full == true) {
Global.rows_cleared +=1;
With objbricks {
Instance_destroy()
Var inst;
Inst = instance_place(x,y,obj);
If inst = no one
Instance_create((objbricks layer.x div 32)*32, (objstarter.y),objbricks);
}}

Objstarter doesn't get deleted but lays a brick when the objbricklayer touches it so bricks can keep being placed after they are cleared, but apparently bricks are not actually being removed...
 

sp202

Member
I'd avoid using "break" if possible. Your code seems a bit convoluted, could you explain again exactly what you're doing and why you require all these collision checks? Screenshots would be helpful.
 
S

Skivenous

Guest
Like I said I typed it all out on my phone, haha, but thanks for the tip. I'm a pretty terrible programmer, I'm better at the art aspect, but! I removed the last 4 lines and that helped, but now it does not place a brick where you end and the line clears...at this point I think all I need really is how could I explicitly tell the game to place a single instance and not stack thousands of objects on top of each other? I tried editing The brick object itself with a code that destroys itself if there's another one in the space, but that doesn't seem to help. Something like

If (place_meeting (x,y,objbrick)) {
Instance_destroy;
}

Other than this the game runs smooth and looks fine.
Sorry for lack of screenshots, my computer does not have internet and I can't upload the pics to the forum from my phone... But thanks for the help!!! (Any other tips on cleaning up the code would welcome too!)
 
S

Skivenous

Guest
I'd avoid using "break" if possible. Your code seems a bit convoluted, could you explain again exactly what you're doing and why you require all these collision checks? Screenshots would be helpful.
Thanks, Man! I had a follow up but I accidentally replied it to my own question lol
 

sp202

Member
I'm still not sure what you're trying to accomplish. My understanding is that you've got a field surrounded by walls with some pre-existing bricks. You take one line at a time and fill it with bricks first in one direction and then the other until you hit a wall or a brick in which case you set row_full to false. But then you destroy them in the very next step?
 
Top