Legacy GM basic for loop

woods

Member
i am trying to understand how the basic for loop works..

i have figured out how to draw my basic toolbar... but how would i make this happen for more than one row?
this gives me a row of ten...
Code:
///draw slots

// draw hotbar bottom center
var my_x = 320
for (i=0; i<10; i++;)
{        
    my_x = my_x+32
    instance_create(my_x,672,obj_slot);
}




//drawing bag slots top right
// draw row 1
var my_x = 704
for (i=0; i<5; i++;)
{        
    my_x = my_x+32
    instance_create(my_x,224,obj_slot);
}

// draw row 2
var my_x = 704
for (i=0; i<5; i++;)
{        
    my_x = my_x+32
    instance_create(my_x,192,obj_slot);
}
// draw row 3
var my_x = 704
for (i=0; i<5; i++;)
{        
    my_x = my_x+32
    instance_create(my_x,160,obj_slot);
}

// draw row 4
var my_x = 704
for (i=0; i<5; i++;)
{        
    my_x = my_x+32
    instance_create(my_x,128,obj_slot);
}

// draw row 5
var my_x = 704
for (i=0; i<5; i++;)
{        
    my_x = my_x+32
    instance_create(my_x,96,obj_slot);
}
how would i make it so it draws more rows of five? (without using another for loop with a different y value)

it works but....
i dont think this second bit is how we should do it?
 
Last edited:

curato

Member
Code:
///draw slots
var my_x = 320
for (i=0; i<10; i++;)
{         
    my_x = my_x+32
    instance_create(my_x,y,obj_slot);
    instance_create(my_x,y-32,obj_slot);
}
 

woods

Member
so simple when you know the answers ;o) thanks curato



Code:
///draw slots

// draw hotbar bottom center
var my_x = 320
for (i=0; i<10; i++;)
{         
    my_x = my_x+32
    instance_create(my_x,672,obj_slot);
}



//drawing bag slots top right
// draw row 1
var my_x = 704
for (i=0; i<5; i++;)
{         
    my_x = my_x+32
    instance_create(my_x,224,obj_slot);
    instance_create(my_x,192,obj_slot);
    instance_create(my_x,160,obj_slot);
    instance_create(my_x,128,obj_slot);
    instance_create(my_x,96,obj_slot);
}
 

GMWolf

aka fel666
You could use a loop inside the loop.
The outer loop loops over he X values. In inner loop loops over the y values.

Or, make a 'create' row function, and call it multiple times.
 

woods

Member
im just trying to figure out how this works so i can get my inventory moving forward.... rather difficult when you dont understand the tools you have available ;o)
 
J

jr carey

Guest
im just trying to figure out how this works so i can get my inventory moving forward.... rather difficult when you dont understand the tools you have available ;o)
theres an easier method:
//drawing bag slots top right
// draw row 1
var my_x = 704
var ii = 0;
for (i=0; i<5; i++;)
{
my_x = my_x+32
repeat(5){
ii++
instance_create(my_x,96*ii,obj_slot);
}
ii = 0
}
try that
 
Top