Before updating to Windows 10 you may need to return your Pro license. More information here

I need help fixing my inventory sorting script.

Basically, this is part of a script that lets me stack items of the same name within each item type list. The problem is, when I first add an item to the curInventory, it causes the size of the stack added to double because it is counted twice.

     function stackItems(){
     var lastItemIndex = curInventory.Count - 1; //the index of the last item in the list
     for(var i: int = 0; i < curInventory.Count;i++){ //for all items in the list
         if(curInventory[lastItemIndex].name == curInventory[i].name){ //if the name of the last item in the list is the same as the name of the 
                                                                       //current item being checked
             if (curInventory[lastItemIndex].stackable == true){ //if the item is able to be stacked
                 if(curInventory[i].stackCount < curInventory[i].maxStack){    //if the number of items currently in the stack is
                                                                                           //less than the max number of items able to stack
                     curInventory[i].stackCount += curInventory[lastItemIndex].stackCount; //increase the stack count of the current item by 
                                                                                           //the number of items in the new stack. This is what causes new items to be counted twice.
                      if (lastItemIndex !=0){

I could really use a fresh set of eyes to help me figure out how I could adjust my current script so that it doesn't count items added to a blank curInventory twice.

more ▼

asked Jul 23, 2013 at 02:44 AM

avatar image

3 4 4 8

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

I know this is prob not gonna get read, you have it going 1, then when stacked its taking the 1 and adding 1, which makes 2, but when it stacks again its not registering as 2 + 1, its going to register as 2 + 2. You need to do something like


then itll register as 1 + 1 = 2, 2+1 = 3 and so on. Sorry for messed up format, first answer on this xD

more ▼

answered Apr 09, 2014 at 04:08 AM

avatar image


(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments



asked: Jul 23, 2013 at 02:44 AM

Seen: 449 times

Last Updated: Apr 09, 2014 at 04:08 AM