for loops to create boxes

hi guys, im having trouble with this script, i want it to add new coordinates for each gui.box made, but it doesn’t work. Can anyone help me out :smile:?

basically i want to create a row of boxes, theres probally an easyer way :stuck_out_tongue:

var Slots = new Array ();
var cap = 10;
var boxcount = 0;
var SlotSpace = new Array();
var Amount = 0;


var X1 : Vector2=Vector2(100,100);
var X = 1;
var Z1 = 100;

function Start () {

}

function Update () {
for(j = 0; j<cap; j++) {
	SlotSpace.Push(Amount);
	}
}


function OnGUI () {
for(i = 0; i < cap; i++) {
	boxcount++;
	Amount = X1.x + X;
	
	GUI.Box(Rect(Amount,X1.y,Z1,Z1),"");
	}
	
}

You didn’t mention what the problem was, but if the problem is that the boxes are all appearing at the same location, that’s because you don’t factor in ‘i’ (the loop counter) anywhere in the code that specifies the box positions.

ok :stuck_out_tongue: cheers for the reply, could you possibly show me how to fix it? i’ve been trying for a while now :confused: i think i’ve confused myself a bit from it.

I’m not sure what you’re attempting to do with the various variables you have there, but if you simply want to create a row of boxes, then the ‘x’ coordinates for each box’s rect should most likely be derived from the value of ‘i’, e.g.:

x = startX + (float)i * buttonWidth;

(The cast to float may or may not be necessary, but it’s just for the sake of illustration.)