Posted By: oldschoolj
Move an array of icons - 09/23/07 15:36
Hi folks, a bit of a problem here wondering if there are any programming gods around lol. I have an inventory thats draggable, the goal is to move the icons around with the inventory. The icons are stored in an array that is[1000] in size. The icons can be constantly moved and resituated in the inventory, because they represent items. Also, everything is dynamic and uses handles, combined with the fact that there are so many items, i can't move them by name. So here is my attempt, and it does move them, but is way slow, and cannot be the RIGHT way of doing it. Thanks for the help 
I thought that first i need to find out what icons are in the inventory, and then where they all are. So i figured I would search the array that they are stored in, and find all of the ones that exist. And then store all of their positions in two arrays (one for x, and one for y) at the same position. And then when I have the mouse button pressed, search the arrays again, and then call up the positions stored in those arrays. Here is the code:
Code:

I thought that first i need to find out what icons are in the inventory, and then where they all are. So i figured I would search the array that they are stored in, and find all of the ones that exist. And then store all of their positions in two arrays (one for x, and one for y) at the same position. And then when I have the mouse button pressed, search the arrays again, and then call up the positions stored in those arrays. Here is the code:
Code:
function ui_drag_inv()
{
var a;
a = minv(999, ( maxv(a, 0))); //between 0-999
a = 0;
while (a < 999)//keep going till we've checked for all existing icons
{
if (item_icon[a] != NULL)//if the panel exists
{
icon_temp_posx[a] = item_icon[a].pos_x; //store its posx in the x_array
icon_temp_posy[a] = item_icon[a].pos_y; //store its posy in the y_array
}
a += 1;
wait (1);
}
var b;
b = minv(999, ( maxv(b, 0)));//between 0-999
b = 0;
while (mouse_left == 1)
{
mouse_pos.x = minv(800 - (bmap_width(ui_inv_bg) - 383), ( maxv(mouse_pos.x, 0 + (bmap_width(ui_inv_bg) - (bmap_width(ui_inv_bg) - 383)))));//the mouse cursor x_limits
mouse_pos.y = minv(600 - (bmap_height(ui_inv_bg) - 23), ( maxv(mouse_pos.y, 0 + (bmap_height(ui_inv_bg) - (bmap_height(ui_inv_bg) - 23)))));//the mouse cursor y_limites
if (item_icon[b] != NULL) //if we've found a icon in the array
{
item_icon[b].pos_x = (mouse_pos.x + icon_temp_posx[b]);//move it to match the mouses pos_x, and add the temp_x that we stored
item_icon[b].pos_y = (mouse_pos.y + icon_temp_posy[b]);//move it to match the mouses pos_y, and add the temp_y that we stored
ui_inv_posx = mouse_pos.x;//move the inventory as well
ui_inv_posy = mouse_pos.y;
}
b += 1;
wait (1);
}
}