loop problem
#1

ok so i create 3 objects into 1 variable with 3 arrays

How the objects are created
PHP код:
   new ID 0;
    while(
ID sizeof (DropObject) && DropObject[playerid][ID])
        {
            
ID++;
        }
    if(
ID == sizeof(DropObject))
        {
            
//arrays are full!
            
return 0;
        }
    
DropObject[playerid][ID] = CreateObject(1685,pX,pY,pZ+82,0.00000000,0.00000000,90.00000000); 
This loops through them all and if near any of them does the function/
PHP код:
new Float:OxFloat:OyFloat:Oz;
for(new 
0sizeof(DropObject); i++)
    {
    
GetObjectPos(DropObject[playerid][i], OxOyOz);
        if(
IsPlayerInRangeOfPoint(playerid4.0OxOyOz))
        {
            
DropObject[playerid][i] =0;
        }else return 
SendClientMessage(playerid,COLOR_RED,"Not Near...!");
    } 
problem: when Check to see what object the player is closes to, only the first created object works WHY ?
is like the loop runs only 1 time :X

SOVLED
Reply
#2

well i have tried many debugs.

first 1
PHP код:
new Float:OxFloat:OyFloat:Oz;
new 
counter=0;
for(new 
0sizeof(DropObject); i++)
    {
        
counter++;
        
GetObjectPos(DropObject[playerid][i], OxOyOz);
        if(
IsPlayerInRangeOfPoint(playerid4.0OxOyOz))
        {
            
DropObject[playerid][i] =0;
        }else return 
SendClientMessage(playerid,COLOR_RED,"Not Near...!"); 
    }
printf("Looped: %d",counter); 
but this didnt even show the print.

Second debug
PHP код:
new Float:OxFloat:OyFloat:Oz;
for(new 
0sizeof(DropObject); i++)
    {
        
printf("%d",DropObject[playerid][i]);
        
GetObjectPos(DropObject[playerid][i], OxOyOz);
        if(
IsPlayerInRangeOfPoint(playerid4.0OxOyOz))
        {
            
DropObject[playerid][i] =0;
        }else return 
SendClientMessage(playerid,COLOR_RED,"Not Near...!"); 
    } 
and that showed me that it looped the same object ID twice, Only if im near the first created object!
otherwise nothing

Edit: i will run more Debugs in a minute, as i have to do something else.
Reply
#3

should be this inside the while?

pawn Код:
if(ID == sizeof(DropObject))
        {
            //arrays are full!
            return 0;
        }
    DropObject[playerid][ID] = CreateObject(1685,pX,pY,pZ+82,0.00000000,0.00000000,90.00000000);
Not sure, because i can't test it, and yea I don't really get that part of code at all, so it's just a suggestion, you should try it.
Reply
#4

Quote:
Originally Posted by Roel
Посмотреть сообщение
should be this inside the while?

pawn Код:
if(ID == sizeof(DropObject))
        {
            //arrays are full!
            return 0;
        }
    DropObject[playerid][ID] = CreateObject(1685,pX,pY,pZ+82,0.00000000,0.00000000,90.00000000);
Not sure, because i can't test it, and yea I don't really get that part of code at all, so it's just a suggestion, you should try it.
no that's not the problem that part of the code works 100%

ok so i figured it out.
i tried to do the first debug again and i saw the else return at the end of the loop and thats what was breaking it.

So thank you: ****** & Roel for ting to help out
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)