A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: array inventory

  1. #1
    Junior Member
    Join Date
    Sep 2006
    Posts
    7

    array inventory

    I am currently working on an rpg, and I need to know how to display objects on an array. I have knowledge of how to use an array (push, pop, shift, etc.) and it is the easiest to use when you want to save a file. And when I remove an item from the inventory how can I make it so it updates objects.

    inventory: knife, apple, potion.

    I remove apple

    inventory: knife, potion.

    Apple is removed from slot 2 and potion is moved to slot 2.

    How can I do this?

  2. #2
    Senior Member dudeqwerty's Avatar
    Join Date
    Mar 2005
    Location
    Bosnia
    Posts
    1,626
    you can just use Array.splice(); like so:
    Code:
    var inventory:Array = ["knife", "apple", "potion"];
    function getIndex(array:Array, item):Number {
    	var z:Number = -1;
    	do {
    		z++;
    	} while (array[z] != item && z != array.length);
    	return z != array.length ? z : -1;
    }
    trace(inventory);
    inventory.splice(getIndex(inventory, "apple"), 1);
    trace(inventory);
    HTH,

    zlatan
    New sig soon

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center