jake13
September 22, 2014, 9:17am
1
I add a new entry to the array with this…
theserver = new TheEnergySevers[currentServer + 1];
theserver[currentServer] = new TheEnergySevers();
theserver[currentServer].freqNumber = ServerNumber;
theserver[currentServer].addPerSec = addMount;
theserver[currentServer].totalAmountCap = Max;
currentServer += 1;
but it deletes the previous element of the array entry for example.
if I add values to the 2 element of the array it makes all the other array element equal o or null.
thanks in advance!
1 Answer
1
dmg0600
September 22, 2014, 9:51am
2
That is because of your first line:
theserver = new TheEnergySevers[currentServer + 1];
Doing this you are overriding the array and erasing all previous values. It seems like you want to use a list.
Wherever you initialize the array put this instead:
List<TheEnergyServers> theserver = new List<TheEnergyServers>();
And change your code for adding a new server to this:
TheEnergyServers newServer = new TheEnergyServers();
newServer.freqNumber = ServerNumber;
newServer.addPerSec = addMount;
newServer.totalAmountCap = Max;
theserver.Add(newServer);
Remember that to use lists you have to add “using System.Collections.Generinc;” at the beginning of the script and that to know the number of elements in the list it goes like “theserver.Count” instead of “theserver.Length”.