Gamestudio Links
Zorro Links
Newest Posts
Newbie Questions
by fairtrader. 12/05/23 14:22
Zorro Trader GPT
by TipmyPip. 12/04/23 11:34
Square root rule
by Smallz. 12/02/23 09:15
RTest not found error
by TipmyPip. 12/01/23 21:43
neural function for Python to [Train]
by TipmyPip. 12/01/23 14:47
Xor Memory Problem.
by TipmyPip. 11/28/23 14:23
Training with command line parameters
by TipmyPip. 11/26/23 08:42
Combine USD & BTC Pairs In Asset Loop
by TipmyPip. 11/26/23 08:30
AUM Magazine
Latest Screens
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Tactics of World War I
Who's Online Now
0 registered members (), 631 guests, and 2 spiders.
Key: Admin, Global Mod, Mod
Newest Members
fairtrader, hus, Vurtis, Harry5, KelvinC
19019 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Move an array of icons #156511
09/23/07 15:36
09/23/07 15:36
Joined: Aug 2005
Posts: 390
Florida
O
oldschoolj Offline OP
Senior Member
oldschoolj  Offline OP
Senior Member
O

Joined: Aug 2005
Posts: 390
Florida
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:
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);
}
}



Last edited by oldschoolj; 09/23/07 15:51.

you can find me with my face in the keyboard, unshaven, listening to some nameless techno tragedy, and hashing through code over a cold cup a stale joe. __________________________________ yours truly
Re: Move an array of icons [Re: oldschoolj] #156512
09/23/07 16:20
09/23/07 16:20
Joined: Jan 2004
Posts: 3,023
The Netherlands
Helghast Offline
Expert
Helghast  Offline
Expert

Joined: Jan 2004
Posts: 3,023
The Netherlands
remove the wait(1); in your first loop.

regards,


Formerly known as dennis_fantasy
Portfolio - http://www.designorhea.com/
Project - http://randomchance.cherrygames.org/
Re: Move an array of icons [Re: Helghast] #156513
09/23/07 21:05
09/23/07 21:05
Joined: Aug 2005
Posts: 390
Florida
O
oldschoolj Offline OP
Senior Member
oldschoolj  Offline OP
Senior Member
O

Joined: Aug 2005
Posts: 390
Florida
Well I finally figured it out. Now I just need to solve the synching problems. But the code works. Here it is, incase it helps anyone who needs to move a massive array of objects at the same time as something else, lol.
Code:
function ui_drag_inv()
{
var a;
a = minv(0999, ( maxv(a, 0000)));
while(mouse_left == 1)
{
a = 0000;
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)))));
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)))));
ui_inv_posx = mouse_pos.x;
ui_inv_posy = mouse_pos.y;
while (a < 0999)
{
if (item_icon[a] != NULL)
{
icon_temp_posx[a] = item_icon[a].pos_x - ui_inv_panel.pos_x;
icon_temp_posy[a] = item_icon[a].pos_y - ui_inv_panel.pos_y;
}
if (item_icon[a] != NULL)
{
item_icon[a].pos_x = ui_inv_posx - bmap_width(ui_inv_bg) + (bmap_width(ui_inv_bg) - 383) + icon_temp_posx[a];//(mouse_pos.x - (bmap_width(ui_inv_bg) + (bmap_width(ui_inv_bg)-383)));
item_icon[a].pos_y = ui_inv_posy - 23 + icon_temp_posy[a];//(mouse_pos.y - (bmap_height(ui_inv_bg) + (bmap_height(ui_inv_bg)-23)));
}
a += 1;
}
wait (1);
}
}




you can find me with my face in the keyboard, unshaven, listening to some nameless techno tragedy, and hashing through code over a cold cup a stale joe. __________________________________ yours truly

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1