A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: RPG Shop Using Arrays

  1. #1
    Senior Member
    Join Date
    Jan 2008
    Posts
    107

    RPG Shop Using Arrays

    Hi all,

    Is there a good as 3.0 tutorial showing you how to use arrays to build a simple rpg shop? Just want to learn a smart way to list all the information (with the Buy buttons).

    Also, how do you people manage the store inventory? Through a XML file?

    Thanks.

  2. #2
    When you know are. Son of Bryce's Avatar
    Join Date
    Aug 2002
    Location
    Los Angeles
    Posts
    838
    It might be worthwhile to search this games forum for these kinda keywords: "rpg" "shop" "inventory" etc. This kind of discussion comes up a lot and it might be hard to find a specific tutorial for it. You should be able to piece it together by searching through old topics.

  3. #3
    Senior Member
    Join Date
    Jan 2008
    Posts
    107
    Did that already. Most of the threads are really old or aren't well explained.

  4. #4
    When you know are. Son of Bryce's Avatar
    Join Date
    Aug 2002
    Location
    Los Angeles
    Posts
    838
    Ok, I checked as well and couldn't find anything good as well.

    So the basic idea is that you have an array that stores all of your items. It would look like this...

    Actionscript Code:
    var playerInventory:Array = ["potion", "potion", "ether", "phoenixdown"];

    If you have different types of items, like armor and equipment, it might be easier to store those in separate arrays at first.

    So you can make an function for the shop buttons.

    Actionscript Code:
    var playerInventory:Array = []; // creates an empty array

    function buyItem( itemType:String, price:int ) : void {
       
        if (itemType == "potion") {
            if (playerGold >= price) {
                playerGold -= price; //subtract price
                playerInventory.push(itemType); // adds item to the end of the array
            }
        } else if (itemType == "ether") {
            if (playerGold >= price) {
                playerGold -= price; //subtract price
                playerInventory.push(itemType); // adds item to the end of the array
            }
        }
        trace("inventory: " + playerInventory); // this will show all items in the inventory
    }

    From there you'll need to determine how you'll use your inventory. You'll have to check the array to fill in your inventory menu screen. You'll have to loop through the array and determine what do with it. If you have a grid of movieclips, maybe you'll switch to the frame of the item.


    Actionscript Code:
    function checkInventory() : void {

        for ( var i:int = 0; i < playerInventory.length; i++) {
            trace("item" + i + " is a: " + playerInventory[i]);
            menu["gridMC" + i].gotoAndStop(playerInventory[i]);
        }
    }

    I'm not sure what your level of understanding is but this should give you an idea of what you need to do.

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