Updatting a variable in array without removing/adding

hi, is it possible to update a variable within an array thats called from a custom function?
for example, i have a quest where you must run and pickup a crate and with my array i have built a quest tracker to show my progress which would say “crate 0/1” and when i pickup the crate i have amount++ but it wont update as i did arr.push from a custom function that isnt called again :S thanks!

var myArray : Array = new Array();
myArray.Push(1);
myArray.Push(9000);
myArray.Push(5);

myArray[0] = myArray[0] + 1;
myArray[1] = 9001;
myArray[2]++;

EDIT: actually, I’m not sure with the ++ example with UnityScript (give it a shot!), but at the very least you can do like: myArray[0] = myArray[0] + 1

awesome, much appriciate it man :smile: and i tried myarray[1] ++ it doesn’t work but everything else does :smile:

Strange though in a label i cant use myarray[0] = myarray [0] + 1 as it will treat at as "write to label myarray[0] 1 " so it would show 01. also if i do myarray[0] + 1 itll give me a error and if i do myarray[0] += 1 it will also show 01. However if i do myarray[0] = “” +1; it seems to clear it and show just 1 XD

I’m not sure I’m quite following what it is you’re doing. Can you post some code from your experiments?

How are you assigning values into your array? Are they strongly typed as integers or are you passing in strings? (if you’re passing in strings, then it will concatenate the values as text, not add them together like numbers)

Perhaps you could also try to use a strongly typed list:

var myValues : List.<int> = new List.<int>();
myValues.Add(9000); //"Add" instead of "Push" with the List class
myValues[0] = myValues[0] + 1;

If you use strongly typed collections, then it’s pretty much impossible for you to accidentally mix and match data types.

its fine they are working fine when i do myarray[0] = “” +1; this works fine, its just strange how the other examples i tried didn’t :stuck_out_tongue: its possibly becuse i have mutiple info in the the single slot.

Wait, you want your results to be “01”?

no :P, my result came out as 01 when i used myarray[0] + 1 or myarray[0] = myarray[0] + 1. However when i used this “myarray[0] = “” + 1” it will come out as just 1. i would post my script but its spread throughout 5

myarray[0] = “” + 1
is the same as
myarray[0] = “1” //note, this is a string, not an integer

I have a feeling that the way you are initially assigning values are turning your numbers into text.

haha probally, as said before, there are mutiple variables in my array [0] for labels, its starting to make more sense in my head :wink: