View Single Post
Muhlex
Junior Member
Join Date: Mar 2019
Old 10-12-2020 , 08:14   Re: Return arrays in ArrayLists by reference
Reply With Quote #7

First of, thanks a lot for taking time out of your day to explain this in detail @Peace-Maker. Awesome write-up and great example!

Quote:
Originally Posted by Peace-Maker View Post
Then you can access the different cells/blocks of every pushed enum struct directly by accessing the block at that offset into the enum struct. You can get the cell offset of an enum struct member using the :: operator like Player::ballEntRef. Cells of an array are called "blocks" in ArrayList terms..
PHP Code:
int ballEntRef players.Get(indexPlayer::ballEntRef); 
Wow, I simply didn't know the :: operator existed. Got how ArrayLists worked up until that point and I seem to have done everything, including setting the correct blocksizes, dependant on the enum struct declaration. This definitely helps in using them that way.

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;

Muhlex is offline