Looping through enum with switch -
MotherDucker - 09.09.2017
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!
Re: Looping through enum with switch -
Paulice - 09.09.2017
pData[i][fData:p]
Re: Looping through enum with switch -
n00blek - 09.09.2017
PHP код:
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;
}
}
Re: Looping through enum with switch -
Misiur - 09.09.2017
This might not work as advertised. If you have any arrays in the enum, it will not go as planned.
Re: Looping through enum with switch -
OneDay - 09.09.2017
Do if not switch
Re: Looping through enum with switch -
MotherDucker - 10.09.2017
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.
Re: Looping through enum with switch -
MotherDucker - 12.09.2017
Bump
Re: Looping through enum with switch -
JasonRiggs - 12.09.2017
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
cannot use letters..
Re: Looping through enum with switch -
OneDay - 12.09.2017
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.
|
not
PHP код:
for(new p = 0; fData:p < fData; p++) {
if(pData[i][FactionRank]==fData:p) {
FactionPayout += Faction_Data[factionid][fData:p];
format(str, sizeof(str), "Employement Pay: %i", Faction_Data[factionid][fData:p]);
break;
}
}