About using loops
#1

Hello. I wanted to as about using loop in this situation:

pawn Код:
public OnPlayerPickUpPickup(playerid,pickupid)
{
     Loop(i,150)
     {
          if(pickupid == Pickup[i])
          {
               code..
          }
     }
     Loop(i,76)
     {
          if(pickupid == EntrancePickup[i])
          {
               code..
          }
     }
     return 1;
}
Will it make a lag to players ?
is it better to use
if(pickupid == Pickip[0]) till Pickup[149] ?
o use switch(pickupid) ?
But it will take a lot of space as a code..
Reply
#2

No. It won't cause 'lag.' Using a loop is the best way of doing it.
Reply
#3

Quote:
Originally Posted by BuLLeT[LTU]
Посмотреть сообщение
if(pickupid == Pickip[0]) till Pickup[149] ?
Checking for each item would be slightly faster but you would need lot more text which would make your file unused big

A switch wont work, switch only work with constant values

Just use a loop like you already did and add a return 1 in it because an item can only be found once
Or add a break (which stops the loop) if some other code should be executed in the callback

pawn Код:
public OnPlayerPickUpPickup(playerid,pickupid)
{
    Loop(i, sizeof Pickup)
    {
        if(pickupid == Pickup[i])
        {
            //code
            return 1;
        }
    }
    Loop(i, sizeof EntrancePickup)
    {
        if(pickupid == EntrancePickup[i])
        {
            //code
            return 1;
        }
    }
    return 1;
}
Reply
#4

I was thinking that i need to use return 1;

Thanks for answers
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)