Jump to content

Enum in for and if condition


Guest xarly

Recommended Posts

I need some help in C++

I need a structure like for, able to go over a enum define, for example

enum QUESTS
{
   QUEST1            = 11111,
   QUEST2            = 22222,
   QUEST3            = 33333,
   QUEST4            = 44444
};

and then

for (uint8 i = 0; i < /*QUESTS LENGHT*/; I++)
{
if ( pPlayer->GetQuestStatus(/*QUESTS [i]*/) == QUEST_STATUS_INCOMPLETE )

...

}

you know what i mean?

I have found solution for C#, but using foreach.

Can you help me?

Thank you!

Link to comment
Share on other sites

In mangos code you will always see something like this:

enum Things
{
   THING_1 = 1,
   THING_2 = 2,
   THING_3 = 3,
   THING_4 = 4
}
#define MAX_THINGS 4

You can also define it as:

enum Things
{
   THING_1 = 0,
   THING_2 = 1,
   THING_3 = 2,
   THING_4 = 3,
   MAX_THINGS
}

In this case, MAX_THINGS is 4 because if an enum isn't given a value, it is always previous + 1.

There is no way to automatically get the length of an enum unfortunately. However, since it's size will never vary dynamically, just make sure to update it.

Link to comment
Share on other sites

Thank you Mango, i didn't realized that option xD

the only thing and maybe the most difficult is the second part, how to compare each value in enum with a condition

enum QUESTS
{
   QUEST1 = 1,
   QUEST2 = 2,
   QUEST3 = 3,
   QUEST4 = 4
}
#define MAX_QUEST 4

for (uint8 i = 0; i < MAX_QUEST ; I++)
{
if ( pPlayer->GetQuestStatus( EACH QUEST# IN ENUM ) == QUEST_STATUS_INCOMPLETE )

...
}

I don't know how do that, maybe it's impossible in this way...

Thank you

Link to comment
Share on other sites

Thank you darkstaller!

but seems that doesn't work :'( it looks like the condition is not evaluated or never is true (even having the quest), but for example i have tried with only a if

if (pPlayer->GetQuestStatus(11111) == QUEST_STATUS_INCOMPLETE)
   {

   }

like this it works, but with for and array doesn't...

I want to know this because i want to start to script some quests, and many of them have the same name but different IDs depending team or faction.

Link to comment
Share on other sites

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. Privacy Policy Terms of Use