c0c0c0 Posted January 31, 2022 Share Posted January 31, 2022 (edited) Let's say I have a sequence of 150 global boolean variables, gBol1 through gBol150, holding either a 0 or a 1.Let's then say that I've been passed another integer global, gIntNeedle = 6, that indicate which of the booleans (gBol6) I want to toggle.The brute force method of matching this up would be 150 if\then statements: if gIntNeedle == 1 gBol1 = 1endIf...if gIntNeedle == 150 gBol150 = 1endIfThat's just ugly. So, is there a way to derive the name of the global boolean from the passed integer and then use that to find the correct variable to toggle? ("gBol" + gIntNeedle) = 1 Also, just to confirm, but there is no such thing as a global array or object that would do this better than 140 variables, right? Edited January 31, 2022 by c0c0c0 Link to comment Share on other sites More sharing options...
DieFeM Posted January 31, 2022 Share Posted January 31, 2022 Unfortunatelly not, there are arrays but are limited to 128 entries, and afaik there's no way to derive the name of a variable. A solution can be using a struct to store 10 booleans, then an array of structs, so by using an array of length 15, multiplied by 10 booleans, you would be storing 150 booleans. Then you should be able to find out the index of the array and the entry in the struct using math, given an index divide it by 10 to find out the index of the array, and modulus to find out the entry of the struct. Link to comment Share on other sites More sharing options...
SKKmods Posted January 31, 2022 Share Posted January 31, 2022 Try dragging the global variables into a formlist in numerical order then use the formlist index: GlobalVariable thisGlobal = myFormlist.GetAt(iIndex) as GlobalVariable No known size limit (I have them at 1024 entries) and not forgetting that index starts at zero. Link to comment Share on other sites More sharing options...
c0c0c0 Posted January 31, 2022 Author Share Posted January 31, 2022 Try dragging the global variables into a formlist in numerical order then use the formlist indexI haven't played with formlists before but that sounds promising. And, hopefully, not terribly fragile. Link to comment Share on other sites More sharing options...
c0c0c0 Posted January 31, 2022 Author Share Posted January 31, 2022 (edited) GlobalVariable thisGlobal = myFormlist.GetAt(iIndex) as GlobalVariable Started this post to beg for more info, then it came to me. This looks like it might work. [EDIT] It absolutely did work. Thanks, guys. Edited February 1, 2022 by c0c0c0 Link to comment Share on other sites More sharing options...
Recommended Posts