Looping through enum with switch
#1

Hi guys! Just a bit confused on how i would do this..

I am trying to make a payday system where it will loop through all of the ranks.. and pay a different amount depending on the rank... However this is my first time looping through an enum and im not quite sure about how to do this.

Here is the code that I've thought of:
Код:
for(new p = 0; fData:p < fData; p++) {
	switch(pData[i][FactionRank]) {
		case p: {
			FactionPayout += Faction_Data[factionid][fData:p];
			format(str, sizeof(str), "Employement Pay: %i", Faction_Data[factionid][fData:p]);
			break;
		}
	        default: break;
        }
}
But with this, I am getting an error on the case line:
Код:
error 008: must be a constant expression; assumed zero
Please help me out, I really appreciate it, will give rep!
Reply
#2

pData[i][fData:p]
Reply
#3

PHP код:
for(new 0; [fData:p] < fDatap++) {
    switch(
pData[i][FactionRank]) {
        case 
p: {
            
FactionPayout += Faction_Data[factionid][fData:p];
            
format(strsizeof(str), "Employement Pay: %i"Faction_Data[factionid][fData:p]);
            break;
        }
            default: break;
        }

Reply
#4

This might not work as advertised. If you have any arrays in the enum, it will not go as planned.
Reply
#5

Do if not switch
Reply
#6

I have changed it with the square brackets around the fData:p but it doesn't work. Just comes up with a tag mismatch, undefined symbol and local variable shadows... So that didn't work.

Quote:
Originally Posted by OneDay
Посмотреть сообщение
Do if not switch
I don't understand? If you mean to switch through all of the ranks and then set it manually? As i have already done this and i am trying it this way to avoid that. But if there isn't a way to do it like this then i'll just revert back to it.
Reply
#7

Bump
Reply
#8

But why the loop? Why not make an enum of rank for the player, and make for example if that enum is equal to 1 give him 1k, etc..

EDIT: btw you get that error because case is being used like that

PHP код:
case 0
cannot use letters..
Reply
#9

Quote:
Originally Posted by MotherDucker
Посмотреть сообщение
I have changed it with the square brackets around the fData but it doesn't work. Just comes up with a tag mismatch, undefined symbol and local variable shadows... So that didn't work.


I don't understand? If you mean to switch through all of the ranks and then set it manually? As i have already done this and i am trying it this way to avoid that. But if there isn't a way to do it like this then i'll just revert back to it.
PHP код:
if 
not

PHP код:
switch 
PHP код:
for(new 0fData:fDatap++) {
    if(
pData[i][FactionRank]==fData:p) {
            
FactionPayout += Faction_Data[factionid][fData:p];
            
format(strsizeof(str), "Employement Pay: %i"Faction_Data[factionid][fData:p]);
            break;
        }

Reply


Forum Jump:


Users browsing this thread: 4 Guest(s)