Which option to use?
#1

These are just examples.

Option 1:

Код:
new ObjectFood[] = { 10, 2000, 400, 200 };


IsFoodObjectPlayer(playerid)
{
	for(new i = 0; i < 4; i++)
	{
	    if(VarPlayerFood == ObjectFood[i]) return 1;
	}
	return 0;
}
Option 2:

Код:
IsFoodObjectPlayer(playerid, VarPlayerFood)
{
	switch(VarPlayerFood)
	{
		case 10, 2000, 400, 200: { return 1; }
	}
	return 0;
}
Reply
#2

fisrt one is have more clear script but a little more memory usage from second one
Reply
#3

If you use the second one, you don't have to store data.

Either way, it's not a big deal if you store the data anyway - You are only putting four entries into your array.
Reply
#4

If your entries are small in number, say only 5-10 entries, i would use the second option.

But if you have more entries or the number of entries may change in future, option one looks more ideal for this.

Also if you didn't know this already:
pawn Код:
// no need to hardcode the size (i.e. 4), you can get the size with sizeof
for(new i = 0; i < sizeof(ObjectFood); i++)
Reply
#5

The second one, no matter how many items, because you are comparing with constant values
The for loop is only neccessary if you are dealing with non-constant values
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)