Hi!

My problem is that I cant create a well-working code to check if the mouse has clicked a building and if it is to show its menu. The properties of all buildings are stored in an array buildings[400]. My function first checks the location of the mouse (works good) and then tries to find it in the building array. Then it recrods the number of the building and calls another function to display the menu.

The problem is that it works only sometimes...

Code:

function check
{
var a=0;
var found=0;
if((mouse_ent!=0)&&(mouse_ent!=MainObject)&&(mouse_ent!=PointerSquare))
{
NodeDetect();//returns x= the location of object
temp=x;
a=0;
found=0;
while(a<=99)&&(found==0)
{

if(temp==buildings[a])//buildings[a] stores the position of every building
{
found=1;
found_no=a;

}

if(a<99)&&(found==0)
{
a+=1;
}

wait(1);
}
}
if(found==1)&&(buildings[found_no+100]==0){ show_menu();} //checks if the building is still under construction
if(found==1)&&(buildings[found_no+100]>0){ show_constr();}
}