I dont know how to do this can someone help?

D

DNgames

Guest
-So im making survival game and i need to make building system i want it to look like this.
-When player enter build mode i want to create those white boxes around him and those boxes are pressed i want to create object that is stored in inventory.
Sprite-0001.png

-I made this by creating it this way :

box 1 = instance_create(x, y, obj_build_spot);
with(box1)
{
x = obj_player.x;
y = obj_player.y-20;
}

-I started doing it for all of the boxes.

So i ask if anyone can show me easier shorter method.
 

Kezarus

Endless Game Maker
Use loops, mate! =]

I cannot verify the code that I made 'cause I don't have GM installed in the machine I am in right now. But try this:

Code:
var cellSize = 20;
var inst;
for(var i=-1; i<=1; i++){
    for(var j=-1; j<=1; j++){
        if( i == 0 && j == 0 ){ continue; }
        inst = instance_create(obj_player.x+(cellSize*i), obj_player.y+(cellSize*y), obj_build_spot);
    }
}
This way you have the variable i for the x component of the vector and j for the y vector. If both are 0 means that you are at the center, so you don't need to create the object. The 'continue' command, makes it go back to the loop instead of continue executing.

Keep experimenting and keep your scope tight! =]
 
D

DNgames

Guest
Use loops, mate! =]

I cannot verify the code that I made 'cause I don't have GM installed in the machine I am in right now. But try this:

Code:
var cellSize = 20;
var inst;
for(var i=-1; i<=1; i++){
    for(var j=-1; j<=1; j++){
        if( i == 0 && j == 0 ){ continue; }
        inst = instance_create(obj_player.x+(cellSize*i), obj_player.y+(cellSize*y), obj_build_spot);
    }
}
This way you have the variable i for the x component of the vector and j for the y vector. If both are 0 means that you are at the center, so you don't need to create the object. The 'continue' command, makes it go back to the loop instead of continue executing.

Keep experimenting and keep your scope tight! =]
Thanks you so much you helped a lot. I forgot i can use for loop i a another for loop to make gird like. Thank you so much!!!
 
Top