Check to see if something is in an array
#6

Quote:
Originally Posted by Vince
View Post
That is incorrect. If the first vehicle doesn't match, it will return the error without even checking the rest of the array. Never return inside a loop unless you explicitly want to break it.
Sorry, you are correct of course. You'd have to break the loop when there is a match. Then after the loop you'd have to check if the index is the size of the array. If not, there was a match so you can sell it, if it is the maximum, you can't.
pawn Code:
new i;
for (i = 0; i < sizeof(RandomRegularVehicle); i++)
    if(CarInfo[idx][cModel] == RandomRegularVehicle[i][0]) break;
if (i == sizeof(RandomRegularVehicle))
    return SendClientMessage(playerid, COLOR_RED, "You cannot sell this type of vehicle here");
Reply


Messages In This Thread

Forum Jump:


Users browsing this thread: 9 Guest(s)