A Flash Developer Resource Site

Page 1 of 2 12 LastLast
Results 1 to 20 of 24

Thread: inventory

  1. #1
    Member
    Join Date
    Mar 2004
    Location
    N. Yorks UK
    Posts
    50

    inventory

    i've done a search on this subject and its been posted a million times but i think i'm even more confused!!

    basically i'm new to flash and i'm making a simple game, i've created about 6 different scenes (not sure if that the best way to go about it) and in each scene are items (mc's) i need to collect (keys for doors, etc).

    i need some kind of inventory that keeps the stuff in throughout the game and obviously the items disappear from scene when collected and dissappear from inventory when used.


    any help would be greatly appreciated.

  2. #2
    Member
    Join Date
    Mar 2004
    Posts
    35
    You could use an object to store the inventory, ie
    inv = new Object();
    inv.key1 = "show";
    inv.key2 = "show";
    inv.key3 = "noshow";

    or an array
    inv = new Array();
    inv[0] = "show";
    inv[1] = "show";

    The beauty of using arrays is that they are easier to manipulate, you can delete instances and then add them back in.

    Best of luck
    Regards,
    Pete

  3. #3
    Member
    Join Date
    Mar 2004
    Location
    N. Yorks UK
    Posts
    50
    thanks fo getting back to me on this but i'm not having much luck. i've just started using flash and maybe i've bit off more than i can chew but i really want to finish this now.

    is there any chance you could explain this as if you were talking to an idiot?




    or point me to tutorial of some kind, i've spent about 4 hours going through old posts and i've got nowhere!


    thanks again.

  4. #4
    Member
    Join Date
    Mar 2004
    Posts
    35
    If you can zip a copy up I will have a look for you.
    Regards,
    Pete

  5. #5
    Junior Member
    Join Date
    Apr 2004
    Posts
    16
    Another thing you might consider would be to have it use a # to tell if you have it or not, for instance, in this frame you are getting the object:

    on (enterFrame){
    var swordisgotten = 1;
    }

    and this would be the frame for the inventory

    on (enterFrame){
    if(swordisgotten == 1){
    inventory1_mc.attachMovie(sword_mc, sword, 1);
    }
    }

    And that would load the sword movie clip into the movie clip representing the first inventory space. Simply set the var back to 0 and it won't load into the inventory. The same concept could be used for wether or not it played in the frame. It's really confusing to work with in big games but it works. If you do it in a different scene you'd need to make the variable _global so that it wouldn't make a new variable every scene. That's documented in the actionscript dictionary in the help.
    Last edited by JaM-DmD; 04-13-2004 at 06:39 AM.
    Ttllyrndm.net - Under Construction

  6. #6
    Member
    Join Date
    Mar 2004
    Location
    N. Yorks UK
    Posts
    50
    cheers jam, that sounds more straight forward, i will give it a go.

  7. #7
    Member
    Join Date
    Mar 2004
    Location
    N. Yorks UK
    Posts
    50
    this is me...

  8. #8
    Member
    Join Date
    Mar 2004
    Location
    N. Yorks UK
    Posts
    50
    say if i have two scenes, in scene 1 i have 2 objects, one called key_mc and one called inventory_mc, and in scene 2 i have 2 objects, one called door_mc and one called inventory_mc.
    all i want to do is to be able to drag the key_mc onto the inventory_mc then go to scene 2 where the key will still be visible and i can drag the key onto the door.

    is there anyway anyone could run through it in the most simple way, i really i'm a complete novice and i'm finding this scripting lark most difficult.

    PS. This game is due to be released in shops in August. RRP £39.99

  9. #9
    Senior Member Adam14's Avatar
    Join Date
    Feb 2004
    Location
    Ontario Canada
    Posts
    1,116
    Does this work for you?

    Adam
    Attached Files Attached Files

  10. #10
    Member
    Join Date
    Mar 2004
    Location
    N. Yorks UK
    Posts
    50
    yeah cheers adam, the actionscript seems fairly simple, i might be able to get my head round it.
    just one question, where did you put the script on the key_btn?? i can't seem to find it.



  11. #11
    Senior Member Adam14's Avatar
    Join Date
    Feb 2004
    Location
    Ontario Canada
    Posts
    1,116
    The key is a button inside the key mc, open the key mc, and click the key and the script is on that...hope this helps

    Adam

  12. #12
    Member
    Join Date
    Mar 2004
    Location
    N. Yorks UK
    Posts
    50
    i know i'm been really stupid here but i've opened up the key, opened the key button... where's the script? i see the up over down hit stages, but nothing in actions??

  13. #13
    Senior Member Adam14's Avatar
    Join Date
    Feb 2004
    Location
    Ontario Canada
    Posts
    1,116
    You don't actually want to go into the key button,...right click on the key movie clip in the library, click edit, then click once on the key in there to make sure it's selected, and then open your actionscript window...

    Adam

  14. #14
    Member
    Join Date
    Mar 2004
    Location
    N. Yorks UK
    Posts
    50
    hello again, i think i've nearly cracked this. what i've done is create two mc's of each object(one in inventory, one on scene) and make the inventory object invisible.

    i've set global variables...
    _global.key="0"
    _global.potion="0"

    and if statements...
    if(_global.key=="1"){
    key_mc._visible=false;
    key1_mc._visible=true;

    but.. when i go through the different movies the inventory is correct unless i return to a previous movie and the variable is reset and the object disappears.

    how do i get round this?

    thanks

  15. #15
    Senior Member Adam14's Avatar
    Join Date
    Feb 2004
    Location
    Ontario Canada
    Posts
    1,116
    Any way you could upload your fla, or email it to me?

    Adam

  16. #16
    Member
    Join Date
    Mar 2004
    Location
    N. Yorks UK
    Posts
    50
    ok mate, i done 2 very simple movies. heres the 1st..
    Attached Files Attached Files

  17. #17
    Member
    Join Date
    Mar 2004
    Location
    N. Yorks UK
    Posts
    50
    and the 2nd..
    Attached Files Attached Files

  18. #18
    Member
    Join Date
    Mar 2004
    Location
    N. Yorks UK
    Posts
    50
    hope my method makes sence.

    as you can see the objects stay in the inventory until you return to the scene where they were picked up, because i'm declaring the variable as "0" again so it disappears.

  19. #19
    Senior Member Adam14's Avatar
    Join Date
    Feb 2004
    Location
    Ontario Canada
    Posts
    1,116
    Ok, I'm a little confused, your scenes aren't scenes in one movie, but rather different swf files called scene1, and scene2?

    Adam

  20. #20
    Member
    Join Date
    Mar 2004
    Location
    N. Yorks UK
    Posts
    50
    sorry yes, they are diffenent files.

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