03.11.2012, 17:39
More good things about enums
3) You can have variables with same name, as long as they belong to different enums
Example:
Usage:
4) You can pass an object attribute as a parameter to a function
For example if you want to make a function that only gives the value of a member variable, but doesn't allow to set it
Usage:
5) You can do this
3) You can have variables with same name, as long as they belong to different enums
Example:
pawn Code:
enum eBoxing
{
bTime
};
new Boxing[5][eBoxing];
pawn Code:
enum eBomb
{
bTime
};
new Bomb[10][eBomb];
pawn Code:
Boxing[boxid][bTime] = 30;
Bomb[bombid][bTime] = 20;
For example if you want to make a function that only gives the value of a member variable, but doesn't allow to set it
pawn Code:
GetVehicleValue(id, eVehicle:item)
{
return Vehicle[id][item];
}
pawn Code:
new lockstatus = GetVehicleValue(id, vLock);
pawn Code:
enum eMenuItem
{
fPrice,
fName[16]
};
new BurgerMenu[][eMenuItem] = {
{40,"Cheese Burger"},
{50,"Huge Burger"},
{30,"Fries"}
};
new PizzaMenu[][eMenuItem] = {
{80,"Large Pizza"},
{60,"Medium Pizza"},
{40,"Small Pizza"}
};
pawn Code:
new MenuItem[eMenuItem];
if(IsPlayerInBurgerShot(playerid))
MenuItem = BurgerMenu[listitem];
else
MenuItem = PizzaMenu[listitem];
if(GetPlayerMoney(playerid) < MenuItem[fPrice])
{
SendClientMessage(playerid, COLOR_RED, "You don't have enough money!");
return 1;
}
GivePlayerMoney(playerid, -MenuItem[fPrice]);
new msg[128];
format(msg, sizeof(msg), "You have bought %s for $%d", MenuItem[fName], MenuItem[fPrice]);
SendClientMessage(playerid, COLOR_WHITE, msg);