F4llfield Posted April 3, 2023 Share Posted April 3, 2023 (edited) Hi, I have a function passing an array. Here is a shorter version of what I'm doing: Armor[] Container0 Armor[] Container1 Armor[] Container2 ; Event OnQuestInit() Container0 = New Armor[10] Container1 = New Armor[10] Container2 = New Armor[10] EndEvent ; Function ChooseArray(Int Whatever) If Whatever == 0 ModifyThisArray(Container0) ElseIf Whatever == 1 ModifyThisArray(Container1) ElseIf Whatever == 2 ModifyThisArray(Container2) EndIf EndFunction ; Function ModifyThisArray(Armor[] thisContainer) thisContainer[0] = myWhatever as Armor EndFunction When later on a function reads for example Container0 array, it's empty. I was thinking that when passing an array as argument, it would be a reference to the array and only the reference would be lost when the function ends. Note: If I make 5 functions ModifyThisArrayX modifying ContainerX without passing the array, it works fine. But I would prefer to have only one function and understand why it's not working. Edited April 3, 2023 by F4ll0uta Link to comment Share on other sites More sharing options...
LarannKiar Posted April 3, 2023 Share Posted April 3, 2023 Not sure what are you trying to accomplish (context would help) but maybe this: ; inserts theArmor to theContainerArray at ElementIndex Function SetArmorInArrayAt(Armor theArmor, Armor[] theContainerArray, Int ElementIndex) If !theArmor || !theContainerArray || ElementIndex < 0 || ElementIndex >= theContainerArray.Length Return None EndIf theContainerArray.Insert(theArmor, ElementIndex) EndFunction Link to comment Share on other sites More sharing options...
F4llfield Posted April 4, 2023 Author Share Posted April 4, 2023 I guess my question is, A. I declare and initialize an array (Container0) so that all function have access to it.B. From a function I pass the array (Container0) as reference named (thisContainer) to another function that will modify his content.C. Later on, an event called function reads the stored information in the Array Container0. I think I should see the changes made to the reference array (but I'm not sure), but for my the array is blank. It didn't kept the changes. Link to comment Share on other sites More sharing options...
F4llfield Posted April 4, 2023 Author Share Posted April 4, 2023 I was able to find a way to do it with one Function by passing the index to the called function instead of the array. I added a few if statement to manage the containers. Link to comment Share on other sites More sharing options...
Recommended Posts