Looping problem
#1

Hi guys, i have problem with looping.

here is code:
Код:
for(new i = 0; i < sizeof(PI); i++)
    {
    if(IsPlayerInRangeOfPoint(playerid, 5.0, PI[i][pPozx], PI[i][pPozy], PI[i][pPozz]))
    {
    SCM(playerid,-1,"Works!");
    return 1;
    }
    else return SCM(playerid,-1,"Not near");
    }
and i have file Ass_0.ini
and Ass_1.ini
and when i come to x,y,z of Ass_0 it says works!
and when i come to x,y,z of Ass_1 it dont work just print Not Near
Reply
#2

Pretty obvious that code can only ever do one loop because of the return in the else
Reply
#3

Quote:
Originally Posted by [uL]Pottus
Посмотреть сообщение
Pretty obvious that code can only ever do one loop because of the return in the else
so how can i make it to work perfect?
Reply
#4

Quote:
Originally Posted by Dusan01
Посмотреть сообщение
so how can i make it to work perfect?
There you go:

Код:
for(new i = 0; i < sizeof(PI); i++)
{
    if(IsPlayerInRangeOfPoint(playerid, 5.0, PI[i][pPozx], PI[i][pPozy], PI[i][pPozz]))
	{
		SCM(playerid,-1,"Works!");
    }
    else
    {
		SCM(playerid,-1,"Not near");
	}
	return 1;
}
Reply
#5

here is code:
pawn Код:
for(new i = 0; i < sizeof(PI); i++)
{
    if(IsPlayerInRangeOfPoint(playerid, 5.0, PI[i][pPozx], PI[i][pPozy], PI[i][pPozz]))
    {
        SCM(playerid,-1,"Works!");
    }   else return SCM(playerid,-1,"Not near");
}
^That might help.

P.S using SCM instead of SendClientMessage is a bad scripting habit.

EDIT: Meh! I was slow D:
Reply
#6

@Lidor124

Yes but when im near file Ass_0 it just print Works, but when im near Ass_1 i first print not near the works :S
Reply
#7

These guys solutions are all retarded.

pawn Код:
for(new i = 0; i < sizeof(PI); i++)
{
    if(IsPlayerInRangeOfPoint(playerid, 5.0, PI[i][pPozx], PI[i][pPozy], PI[i][pPozz]))
        return SCM(playerid,-1,"Works!");
}
return SCM(playerid,-1,"Not near");
Reply
#8

Quote:
Originally Posted by [uL]Pottus
Посмотреть сообщение
These guys solutions are all retarded.

pawn Код:
for(new i = 0; i < sizeof(PI); i++)
{
    if(IsPlayerInRangeOfPoint(playerid, 5.0, PI[i][pPozx], PI[i][pPozy], PI[i][pPozz]))
        return SCM(playerid,-1,"Works!");
}
return SCM(playerid,-1,"Not near");
Thanks bro REP+
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)