Quote:
Originally Posted by Muhlex
One more follow-up question about my example... I'm writing up a basic minigame that (hypothetically) may have multiple instances running simultaneously with different clients on a server belonging to different games. Now I could still use a static Player players[MAXCLIENTS + 1] array per game, however as it is (understandably) not allowed to set multidimensional fields on an enum struct, I could not add the players as a field for e. g. a Game struct.
Is there a workaround that doesn't defeat the purpose of the enum struct syntax, achieving something like this?
PHP Code:
enum struct Player {
int client;
int someOtherData;
}
enum struct Game {
Player players[MAXPLAYERS + 1]; // not allowed
int winnerOrWhatever;
}
|
If the number of players is low like 4 you could just add "player1", "player2", "player3" manually, but that's ugly. You could define a maximum number of simultaneous games and reference another global array.
PHP Code:
#define MAX_GAMES 10
enum struct Player {
int client;
int someOtherData;
}
Player players[MAX_GAMES][MAXPLAYERS+1];
enum struct Game {
int index;
int winnerOrWhatever;
void DoStuff() {
this.winnerOrWhatever = players[this.index][0].client;
}
}
Game games[MAX_GAMES];
public void thing() {
// Find free game slot
int index = -1;
for (int i; i < MAX_GAMES; i++) {
if (games[i].index == -1) {
index = i;
break;
}
}
Game game;
game.index = index;
games[index] = game;
}
I don't think there's a common way for things like this.
Quote:
Originally Posted by Muhlex
Another thing... Is it possible to retrieve a method from an enum struct which is stored in an ArrayList and then execute it, without getting a full copy of the enum struct?
|
No, to access the fields you have to have a local copy.
__________________