Hello,
how would I create a dynamically sized enum struct array? Are they even possible or can I do something similar?
My Problem:
Spoiler
PHP Code:
enum struct Thing {
int value;
}
Thing things[]; // i dont know
public void OnPluginStart() {
int size = LoadSizeFromConfig();
things = new Thing[size]; //does not work
}
So instead I tried storing the struct inside an ArrayList.
However all values set are lost inside it:
Spoiler
PHP Code:
enum struct Thing {
int value;
}
ArrayList list;
public void OnPluginStart() {
list = new ArrayList();
Thing t;
t.value = 5;
list.PushArray(t);
Thing t2;
list.GetArray(0, t2);
PrintToServer("%i", t2.value);
// value = 5
}
Does anyone know if I can do something like this?
EDIT:
My above example seems to work, however when there are more properties inside an enum struct it does not change:
Spoiler
PHP Code:
enum struct Thing {
int value;
int value2;
}
ArrayList list;
public void OnPluginStart() {
list = new ArrayList();
Thing t;
t.value2 = 5;
list.PushArray(t);
Thing t2;
list.GetArray(0, t2);
PrintToServer("%i", t2.value2);
// value = 0 ???
}
EDIT 2:
Alright I figured out that I need to put a blocksize inside the ArrayList constructor.
Working Example:
Spoiler
PHP Code:
enum struct Thing {
int value;
int value2;
}
ArrayList list;
public void OnPluginStart() {
list = new ArrayList(sizeOf(Thing)); // The fix!
Thing t;
t.value2 = 5;
list.PushArray(t);
Thing t2;
list.GetArray(0, t2);
PrintToServer("%i", t2.value2);
// value = 5 !
}
Sorry for the troubles