How should i create a permanent reference to an object

okay so i’ve recently learned that there are no formal pointers in javascript(??) what’s the best way to create a permanent reference to a dynamic object? i have a class in a game called ‘level’ that has all the information for that level and does all the processing for all the level objects etc, i’d like to have a general pointer called like ‘game level’ that references which level is currently being played. what’s the best way to do that without formal pointers? thanks

1 Like

you can create a singular object that is represents a specific level

ArrayList<Level> levels = new ArrayList<Level>();
int c = 0;
Level current = levels.get(c);

void setup() {
    ...
}
void draw() {
    current.display();
}
void setLevel(int value) {
    c = value;
    current = levels.get(c);
}

hmm yea that was my backup plan, just to make an array with all the levels in it. is there really no way to make like an actual pointer to a level though?

what do you mean with “pointer”. Do you mean a way to reference a specific object?

If you do you can always just do something like:

int c = 0;
void draw() {
    Level current = getLevel(c);
}

Level getLevel(int id) {
   return ( levels.get(id) );
}

it would be enough to store currentLevel and use it as an index for levels

1 Like

Its here : P
(just filling some text to get 20 chars)

1 Like