K
Karlabos
Guest
Hi.
I am trying to code my inventory stuff.
So far I have an inventory with 'mymaxitems' slots and the latest slot which actually contains an item is the number (mytotalitems)th. It turns out every item of the inventory is an instance of obj_Item, for which then I assign the sprite and the other properties as they appear in the game.
I am trying to code the item usage, and part of the script is as follows:
for(j=localitemindex;j<=localobjtocheck.mytotalitems;j+=1){
if localobjtocheck<localobjtocheck.mytotalitems{ //i had to include this so that j+1 part didn't return error
localobjtocheck.item[j] = localobjtocheck.item[j+1];
localobjtocheck.item[j].name = localobjtocheck.item[j+1].name;
localobjtocheck.item[j].sprite_index = localobjtocheck.item[j+1].sprite_index;
}
}
localobjtocheck.item[localobjtocheck.mytotalitems] = obj_Empty;
localobjtocheck.item[localobjtocheck.mytotalitems].name = "";
localobjtocheck.mytotalitems-=1;
So in my view the for part should vary j from the item to be used (whose number is localitemindex) until the last slot containing an item (localobjtocheck.mytotalitems, I have to call object from other object because it's not the one executing the script)
Then while j varies in this for, every slot should receive the properties of the next one, so if I'm using the 2nd item from an invetory with 4 items, then 1 stays as it is, 2 becomes 3, 3 becomes 4 and the for ends. So I
end up with an item sequence 1,3,4,4 of kinds.
For the part of the code after the code, it's only the last object vanishing from the inventory, hence staying with a sequence 1,3,4. So with this item 2 should have vanished from the inventory and all the other items should have walked to the prior position, right?
However it's not what happens... What happens is that every item of the inventory disappears!
And after that, if I get another item from the room, then instead of appearing only one, the whole inventory is filled of items of that kind, up until mymaxitems... This last part happens only if I have already used an item from the inventory, before that the colliding/getting an item part is working fine, so I suspect the error must be here...
Any idea on why this happens?
I am trying to code my inventory stuff.
So far I have an inventory with 'mymaxitems' slots and the latest slot which actually contains an item is the number (mytotalitems)th. It turns out every item of the inventory is an instance of obj_Item, for which then I assign the sprite and the other properties as they appear in the game.
I am trying to code the item usage, and part of the script is as follows:
for(j=localitemindex;j<=localobjtocheck.mytotalitems;j+=1){
if localobjtocheck<localobjtocheck.mytotalitems{ //i had to include this so that j+1 part didn't return error
localobjtocheck.item[j] = localobjtocheck.item[j+1];
localobjtocheck.item[j].name = localobjtocheck.item[j+1].name;
localobjtocheck.item[j].sprite_index = localobjtocheck.item[j+1].sprite_index;
}
}
localobjtocheck.item[localobjtocheck.mytotalitems] = obj_Empty;
localobjtocheck.item[localobjtocheck.mytotalitems].name = "";
localobjtocheck.mytotalitems-=1;
So in my view the for part should vary j from the item to be used (whose number is localitemindex) until the last slot containing an item (localobjtocheck.mytotalitems, I have to call object from other object because it's not the one executing the script)
Then while j varies in this for, every slot should receive the properties of the next one, so if I'm using the 2nd item from an invetory with 4 items, then 1 stays as it is, 2 becomes 3, 3 becomes 4 and the for ends. So I
end up with an item sequence 1,3,4,4 of kinds.
For the part of the code after the code, it's only the last object vanishing from the inventory, hence staying with a sequence 1,3,4. So with this item 2 should have vanished from the inventory and all the other items should have walked to the prior position, right?
However it's not what happens... What happens is that every item of the inventory disappears!
And after that, if I get another item from the room, then instead of appearing only one, the whole inventory is filled of items of that kind, up until mymaxitems... This last part happens only if I have already used an item from the inventory, before that the colliding/getting an item part is working fine, so I suspect the error must be here...
Any idea on why this happens?