View Single Post
Muhlex
Junior Member
Join Date: Mar 2019
Old 10-13-2020 , 07:06   Re: Return arrays in ArrayLists by reference
Reply With Quote #8

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? Similar to how Peace-Maker explained retrieving a field on an enum struct stored inside of an ArrayList.

Somewhat pseudo-code:
PHP Code:
enum struct Thing {
  
int someValue;

  
void ChangeValue() {
    
this.someValue 1234;
  }
}

Function 
MyFunc arrayListOfThings.Get(0Thing::ChangeValue);
Call_StartFunction(INVALID_HANDLEMyFunc); 
Instead of

PHP Code:
Thing myThing;
arrayListOfThings.GetArray(0myThing); // creates a copy
myThing.ChangeValue();
arrayListOfThings.SetArray(0myThing); // need to do this because the method changes the field on the copy only 
Or should I rather just not care / does this approach not make sense, so that I need to stick to the second way of doing it?

EDIT: I just realized that not making a copy of the enum struct before executing it's method would also allow the method to change the enum struct's fields directly. At least that is what I'm hoping for. Updated the examples to reflect what I'm trying to achieve.

Last edited by Muhlex; 10-13-2020 at 07:47.
Muhlex is offline