break and return -
GaGlets(R) - 27.12.2010
Here I`m again..
Now with small problem but will be nice to know.
How could i stop script (return) and use break in one time?
Reason is, i want to stop forwarded script and break a loop.
pawn Код:
for(new h = 0; h < sizeof(HouseInfo); h++)
{
if(IsPlayerInRangeOfPoint(playerid, 2.0, HouseInfo[h][hEntrancex], HouseInfo[h][hEntrancey], HouseInfo[h][hEntrancez]))
{
if(HouseInfo[h][hOwned] == 1)
{
if(HouseInfo[h][hRentabil] == 0)
{
//script
}
else
{
//script
}
}
else
{
// script
}
break; // here i want to break and return to not allow next loop
}
}
for(new h = 0; h < sizeof(SBizzInfo); h++)
{
`break; // here i want to break and return something to not allow next loop`
How would i do that in my case?
Tried things like:
pawn Код:
return break;
//---
break;
return 1;
//----
Re: break and return -
1337connor - 27.12.2010
a method I always like is
new count;
and when you break
count++;
make a if statement, seeing if(count > 1) { Dont run the code } else { Run the code }
Re: break and return -
GaGlets(R) - 27.12.2010
That would be the last what would i use if there are more solutions. (i`m thinking about code optimisation not deoptimisation
)
Re: break and return -
randomkid88 - 27.12.2010
It has to be placed in an if() or else() statement I believe. Because if the house is owned or not, "break" is never executed. Can you explain a little bit more where/why you want it to break?
Re: break and return -
GaGlets(R) - 27.12.2010
ofcourse.
I want to break loop because it would totally run to 1000 and if player got things in 500 then i would not run loop for nothing if you know what i mean.
pawn Код:
for(new h = 0; h < 1000; h++)
{
if(h == 500)
{
he got things...
// i dont want to loop another 500 so - break and i dont want to create next loop for nothing - return somehow.
}
}
for(next loop to about 200)
{ ....
Re: break and return -
randomkid88 - 27.12.2010
In that case, you would put break; after "he got things". This would stop the loop there and the code would go on to your next loop. Hope that helps.
Re: break and return -
GaGlets(R) - 27.12.2010
but then i need to stop second loop to and again the same problem..
Re: break and return -
FUNExtreme - 27.12.2010
break will stop the loop from excecuting which is what you want.
Return stops everything after that from being excecuted.
The example in the first post will work as you want, it is advised to put the return at the end of the callback otherwise everything after the first loop won't be excecuted.
pawn Код:
// Loop 1
// Loop 1 returns true for your if statement
break;
// Loop 2 (Which is a new loop under Loop 1 like in your example)
// Loop 2 ends
return 1;
Hope this helps
Re: break and return -
GaGlets(R) - 27.12.2010
If yould see all my code.
These loops are under OnPlayerPickupPickup.
After loops it checks player position (InRangeOf) but if something was done in loop then i want to break current loop and stop script from continuing.
Ofcourse i know how to do that but that is last thing what would i do, I`m hoping on you...
Re: break and return -
iggy1 - 27.12.2010
I think i get what you mean here is an example of what id do.
pawn Код:
new goal;
for(new h = 0; h < sizeof(HouseInfo); h++)
{
if(IsPlayerInRangeOfPoint(playerid, 2.0, HouseInfo[h][hEntrancex], HouseInfo[h][hEntrancey], HouseInfo[h][hEntrancez]))
{
if(HouseInfo[h][hOwned] == 1)
{
if(HouseInfo[h][hRentabil] == 0)
{
//script
}
else
{
//script
}
}
else
{
// script
}
goal = 1;//you would need a variable to stop the next loop
break; // here i want to break and return to not allow next loop
}
}
if(goal == 1)return 1;//if the loop found what it was looking for return 1
for(new h = 0; h < sizeof(SBizzInfo); h++)
{
}