Jump to content

Enum in for and if condition


Recommended Posts

Posted

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!

Posted

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.

Posted

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

Posted

Power to the imagination! gg i found solution probably not the most optimal but should work

defining a struct, then a variable type array with that struct and its done

Thank you anyway

Posted

something like this?

static uint32 const Quests[] =
{
   11111,  // quest 1
   22222,  // quest 2
   33333,  // quest 3
   44444   // quest 4
};

for (size_t i = 0; i < sizeof(Quests)/sizeof(uint32) ; ++i)
{
   if (pPlayer->GetQuestStatus(Quests[i]) == QUEST_STATUS_INCOMPLETE)
   {
       // do stuff
   }
}

Posted

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.

×
×
  • 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