SMB92 Posted July 26, 2017 Share Posted July 26, 2017 Hi folks, So I'm looking at reducing the amount code involved in my functions, but my use of arrays is quite complex and it's getting a bit confusing so I'm hoping to get a second opinion/fresh eyes on what I'm trying to do. So what we have is a series of full property arrays of the struct type, (which I prefill of course). This contains information/variables for a type of actor who could possibly be getting spawned. Then we have a private property arrays of the struct type, which are filled at runtime with members of the full property arrays. So for example we have ActorTypeStruct[] Property RaiderG1Properties Auto and we have ActorTypeStruct[] ActorTypes_RS_R1 (Full and private). The members of the full property are information for this type of spawn for each region, so at index 0 the struct would be for Region 1 (we have 13 regions at present, 13 "divisions" of the Commonwealth). The members of the private property array are to be dynamically filled with ActorTypeStruct members from various arrays like RaiderG1Properties, (based on a setting bAllowed) Have a look at the following example code I wrote, this is what I am trying to optimize into a single or fewer functions: Function FillDynamicArray_SingleRegion_RS(Int iRegion) ;ActorTypes_RS_R1 = new ActorTypeStruct[0] ;Left for reference, moved to new loop method ActorTypeStruct[] ActorTypes_RS_Temp = new ActorTypeStruct[0] ;Temp array to mirror to private property later ActorTypeStruct tmpStruct ;tmpstruct for casting full property member to if RaiderG1Properties_RS[iRegion].bAllowed == true tmpStruct = new ActorTypeStruct ; create a new temporary var of the struct type tmpstruct = RaiderG1Properties_RS[iRegion] ;Cast the struct from array to temp variable ActorTypes_RS_Temp.Add(tmpstruct) OR ActorTypes_RS_Temp.Add(RaiderG1Properties_RS[iRegion]) endif if iRegion == 1 ActorTypes_RS_R1 = ActorTypes_RS_Temp ActorTypes_RS_Temp.Clear() elseif iRegion == 2 ActorTypes_RS_R1 = ActorTypes_RS_Temp ActorTypes_RS_Temp.Clear() EndFunction Alternative: Function FillDynamicArray_SingleRegion_RS(Int iRegion) ;ActorTypes_RS_R1 = new ActorTypeStruct[0] ;Left for reference, moved to new loop method ActorTypeStruct[] ActorTypes_RS_Temp = new ActorTypeStruct[0] ;Temp array to mirror to private property later ActorTypeStruct tmpStruct ;tmpstruct for casting full property member to if iRegion == 1 ActorTypes_RS_Temp = ActorTypes_RS_R1 elseif iRegion == 2 ActorTypes_RS_Temp = ActorTypes_RS_R2 endif if RaiderG1Properties_RS[iRegion].bAllowed == true tmpStruct = new ActorTypeStruct ; create a new temporary var of the struct type tmpstruct = RaiderG1Properties_RS[iRegion] ;Cast the struct from array to temp variable ActorTypes_RS_Temp.Add(tmpstruct) OR ActorTypes_RS_Temp.Add(RaiderG1Properties_RS[iRegion]) endif EndFunction Note there may be some mistakes there, but you should be able to see where I am going here. It is also very incomplete, let us say that there are 40 more full property arrays that I will need to go through. Any useful advice appreciated. Thx Link to comment Share on other sites More sharing options...
SMB92 Posted July 26, 2017 Author Share Posted July 26, 2017 Alright so after looking a bit better, I realised its better to mirror the temp array at the end after all edits made. Here is better start to code, the direction I'm going at present: Function FillDynamicArray_SingleRegion_RS(Int iRegion) ;ActorTypes_RS_R1 = new ActorTypeStruct[0] ;Left for reference, moved to new loop method ActorTypeStruct[] ActorTypes_RS_Temp = new ActorTypeStruct[0] ;Temp array to mirror to private property array later ActorTypeStruct tmpStruct ;tmpstruct for casting full property struct member to private array ;Need to cast temp array to private property array last because editing the temp array won't reflect in private array. ; if RaiderG1Properties_RS[iRegion].bAllowed == true tmpStruct = new ActorTypeStruct ; create a new temporary var of the struct type tmpstruct = RaiderG1Properties_RS[iRegion] ;Cast the struct from array to temp struct of same type ActorTypes_RS_Temp.Add(tmpstruct) ;Add the temp struct to temp array ;OR ;ActorTypes_RS_Temp.Add(RaiderG1Properties_RS[iRegion]) ;if can be cast directly from array to array endif if RaiderG2Properties_RS[iRegion].bAllowed == true tmpStruct = new ActorTypeStruct ; create a new temporary var of the struct type tmpstruct = RaiderG2Properties_RS[iRegion] ;Cast the struct from array to temp struct of same type ActorTypes_RS_Temp.Add(tmpstruct) ;Add the temp struct to temp array ;OR ;ActorTypes_RS_Temp.Add(RaiderG1Properties_RS[iRegion]) ;if can be cast directly from array to array endif ;Reason for temp array is because loop needs to know which array is getting all this data. Converted here. if iRegion == 1 ActorTypes_RS_R1 = ActorTypes_RS_Temp ActorTypes_RS_Temp.Clear() elseif iRegion == 2 ActorTypes_RS_R2 = ActorTypes_RS_Temp ActorTypes_RS_Temp.Clear() elseif iRegion == 3 ActorTypes_RS_R3 = ActorTypes_RS_Temp ActorTypes_RS_Temp.Clear() elseif iRegion == 4 ActorTypes_RS_R4 = ActorTypes_RS_Temp ActorTypes_RS_Temp.Clear() elseif iRegion == 5 ActorTypes_RS_R5 = ActorTypes_RS_Temp ActorTypes_RS_Temp.Clear() elseif iRegion == 6 ActorTypes_RS_R6 = ActorTypes_RS_Temp ActorTypes_RS_Temp.Clear() elseif iRegion == 7 ActorTypes_RS_R7 = ActorTypes_RS_Temp ActorTypes_RS_Temp.Clear() elseif iRegion == 8 ActorTypes_RS_R8 = ActorTypes_RS_Temp ActorTypes_RS_Temp.Clear() elseif iRegion == 9 ActorTypes_RS_R9 = ActorTypes_RS_Temp ActorTypes_RS_Temp.Clear() elseif iRegion == 10 ActorTypes_RS_R10 = ActorTypes_RS_Temp ActorTypes_RS_Temp.Clear() elseif iRegion == 11 ActorTypes_RS_R11 = ActorTypes_RS_Temp ActorTypes_RS_Temp.Clear() elseif iRegion == 12 ActorTypes_RS_R12 = ActorTypes_RS_Temp ActorTypes_RS_Temp.Clear() elseif iRegion == 13 ActorTypes_RS_R13 = ActorTypes_RS_Temp ActorTypes_RS_Temp.Clear() endif SystemsIOIndex_R1[0] = true EndFunction EDIT - Bot methods seen in that code compile, will test tomorrow. Hopefully the commented out way will work fine Link to comment Share on other sites More sharing options...
Recommended Posts