best way to store a big amount of dynamic data

hey I’m doing a chemical simulator… kind of

i made a inventory system that adds the name of your newly “mined” atom and keeps track of the amount. this is in an open world with more or less 50 different atom types scattered. then you can go to your lab and start chemical processes (binding, heating, freezing, splitting,…) later in the game this gives you resources to make things like concrete walls or parts for machines or simply water or fresh air ect…

now I started with using arrays, both Builtin and js. for example one for the type of atom and one for the amount one for the amount of electrons it has,…
but since i started building the lab and need the data there and want to do more complex calculations on it I’m wondering if there isn’t a way where i can store the Type together with it’s amounts and so on in something like an array where every index spot can keep track of all the variables for one type of atom?
I’m learning programming by myself for over a year now so I’m used to making it work with what i know, thats why i get the feeling there’s something very handy like this i just don’t know of.

don’t know if i need to post my code for this, just tell me if it is.

You can turn your multiple arrays into a “single” array by using base classes to represent the entries and use them to form a “master” array.

Assume the values for each entry were these : AtomicName, AtomicWeight, Quantity where AtomicName and AtomicWeight are provided at start (initialized to the actual element values) and the Quantity changes over time as stuff is mined. The class representing an entry in the atomic array would be something like this.

//Atomic entry class data holder definition
public class AtomicArrayEntry
{
public var AtomicName : String; //this will be set in the inspector
public var AtomicWeight : int ;//this will be set in the inspector
public var Quantity : float=0; //this will change as stuff gets mined used
}

There are a few different methods on how to go about implementing this type of class but for this use it’s simply to hold data and won’t need to process stuff like Update() or Start() therefore it won’t need to derive from a monobehaviour and can be simply made part of the script where you stored your old arrays and you will access it from the inspector hierarchy window to setup specific values.

Modification to existing script controlling the atomic arrays

//Depreciated arrays
//public var AtomicName : String[];
//public var AtomicWeight : int[];
//public var AtomQuantities : float{};

//PeriodicQuantityTable represents the three combined arrays into an array of class entries
public var PeriodicQuantityTable : AtomicArrayEntry[];

public class AtomicArrayEntry
{
public var AtomicName : String;
public var AtomicWeight : int;
public var Quantity : float=0;
}

So with this modification complete in the editor inspector you can set the size and initial values of the names in the PeriodicQuantityTable. So with 10 elements you’d set the size to 10 and then fill in the name weight values for each entry.

References to the specific atomic entry would then be:

PeriodicQuantityTable[×].AtomicName
PeriodicQuantityTable[×].AtomicWeight
PeriodicQuantityTable[×].Quantity

Where x = index in the PeriodicQuantityTable of the specified element.

beautyfull thanks I’ll try that right away!

Could also use a List<> you need to add types dynamically

@ BPPherv thanks again comes in handy to know.

I’m a bit confused now with the difference between a public function and a public class and when to use what…

Like i said I’m doing this mining thing and then the laboratory where you can do 4 main things: boil, freeze, mix and split

I have 4 objects for that in the scene, in the GUI if have the elements in your inventory together with the amounts. so now you can drag an element from your inventory into 1 of the four objects and it adds it to the loop for your chemical cook .

the cooking is no more then getting the elements names check the amount and the number of electrons, in a for loop. and sending the result to a function that calculates a string that comes out and renders to the GUI atm.
this is all in my cooking script. on my objects i only have a public class like BPPherv showed me above and a public array that keeps the name/amount/nr of electrons of elements in circulation.

so my question is, should i better split up the calculations for the 4 objects and makes public classes or functions in each there own script. As now all these will be sitting in one function that gets run with constantly checking for loop accessing the script of the object with only the array of elements?

this is the for loop i use and the function it calls:

//one of the 4 for loops to get the elements dropped in one of the 4 bottles
if(selected  tool=="mix")
		{	
			
			//var bind:boolean;
			Debug.Log(obj.GetComponent(elementsAmount).elements.length);
			
			GUILayout.Label("mixing container");
			if(obj.GetComponent(elementsAmount).elements.length>3)
			{
				scrollPosition=GUILayout.BeginScrollView (scrollPosition);
				GUILayout.BeginVertical();
				for (var e=0; e<obj.GetComponent(elementsAmount).elements.length; e+=3)
				{	
					for(var a=3+e; a<obj.GetComponent(elementsAmount).elements.length; a+=3)
					{	
						
						var moleculeE:String=obj.GetComponent(elementsAmount).elements[e];
						var moleculeA:String=obj.GetComponent(elementsAmount).elements[a];
						var elektronE:int=obj.GetComponent(elementsAmount).elements[e+1];
						var elektronA:int=obj.GetComponent(elementsAmount).elements[a+1];
						var amtE:int=obj.GetComponent(elementsAmount).elements[e+2];
						var amtA:int=obj.GetComponent(elementsAmount).elements[a+2];
						setBox(moleculeA,elektronA,amtA,moleculeE,elektronE,amtE);
						GUILayout.Box(GUIString);
					}
				}
				
				GUILayout.EndVertical();
				GUILayout.EndScrollView();
				
			}
//example of what the function should do
function setBox(NH:String,eH:int,AH:int,NL:String,eL:int,AL:int)
{	
	if(NH!=NL  (eH+eL)/(AH+AL)==8 || (eH+eL)/(AH+AL)==1)
	{
		GUIString=AH+""+NH+""+AL+""+NL+""+(eH+eL);
	}
	
	if(NH==NL  AH==AL  eH==eL)
	{
		GUIString=(AH+AL)+""+NH+""+(eH+eL);
	}
}

I don’t think there’s a right or wrong way to go about this. Personally I’d go with leaving the actual cook methods as functions of a single cooker control script and process the 4 GUI elements and their data through that. So your current setup with the cooking methods as functions of a single script makes sense to me even if I wasn’t quite sure what you were trying to ask in your last post.

well it struck me i could go the same way as you showed about it. Instead of calculating every cooking proces in the one function in the cooking script i could make public classes of each cooking function in the script of the cooker itself. this is maybe easier to use throughout the whole game then a function