I didn’t think that I will post again so soon here!
But sadly I didn’t find much on topic and once again I think that only experts here could give me a hand. I’m asking for a bit of guide on solving this issue !
Let me try to explain what I’m trying to achieve !
I have 25 int arrays that hold 25 elements in them (each).
Each array is holding information about cities on map scene.
Once player clicks on city, GUI pops up and shows all information from Array that is responsible for that city.
Players can also trade with that city (buying or selling) but they can only sell 1 unit or 10 units, same goes for buying.
Now I need to program all this.
I have an gameObject named “Informations” that holds “CityInformation” script.
That script defines arrays and handles values on new game, loading or saving.
Each city has “Cityclickinfo” script attached to it.
This script accesses CityInformation script and pulls array informations.
I’m capable of writing line by line for each array like this :
// If player clicks sell button for this product
ArrayCityName[1] -= 10;
// if player clicks sell button for this other product
ArrayCityName[2] -= 10;
//...
// If player clicks buy for apples
ArrayCityName[5] += 10;
//...
ArrayCityName[24] += 1;
//... Then write code for another city, covering every button for each array and so on and so on.
But this would leave me with thousands of lines of code! And since I’m doing same thing for each array I want to do it in one stroke, dynamically !
What I was thinking is to have one variable that identifies city and then according to that value write code that would be universal for each array.
Something like this :
var CityID ;
// Player clicks "sell10" on city with ID1
Array1[1] += 10;
Array1[2] += 10;
//...
// Player clicks "sell 10" on city with ID2
Array2[1] +=10;
//...
Except that I wouldn’t write it like that, for each array, but rather have that “Array1” and “Array2” field depending on the CityID and then using one stroke of codes for each array.
I’m asking for guide here as in - what do I have of options?
I wanted to make an Array consisting of my 25 arrays, and then use index as ID, but that didn’t go well.
I’m using JS. Do keep in mind that I’m accessing those arrays from another script using
var info : CityInformation;
// Example of usage
Debug.Log (info.Tronskar[0]);
Any guide towards handling this is greatly appreciated, it wont help me just now but I will try to shorten similar code in future for every problem I run into ! I’m really curious about it generally !
Thanks !
// What I checked so far :
http://docs.unity3d.com/ScriptReference/Array.html
http://forum.unity3d.com/threads/array-of-arrays.26622/
http://forum.unity3d.com/threads/array-of-arrays.26622/