PDA

View Full Version : Game Inventory



Robman1
May 25th, 2004, 12:59 AM
I am basically a noobie to the actionscript world and I have only touched base with the basics. However I have learned a lot on my own. (I know this isnt much of an accomplishment seein as how the commands are in English) Anyway, to get to the point.
I am making a basic game where you explore different parts of a school and I am basically making fun of the teachers at my school. The point of the game is to get detentions (maybe) if not I would still need to know how to hold other items the user finds.
Does anybody know how to do this? I want to be able to click and object and then its in an inventory. Help is appreciated.

Blackspirit
May 25th, 2004, 09:27 AM
ok, let me see.
Put this in your actions frame....

var inventorySize=6, numItemsCarried=0;
var inventory=new Array(inventorySize); //array of inventory

//adds items to inventory, need to pass item name as paramater
Function addItemtoInventory(itemName){
if(numItemsCarried<inventorySize){ //if your inventory isnt full
inventory[numItemsCarried]=itemName;
numItemsCarried++; //adds one to amount of items carried
}
}

Maybe this in your item movie clip. You need a variable in it to state its name

on(release){
var itemName="Rubber Ducky";
addItemtoInventory(this.itemName); //calls function with its item name
}

that might work.

Robman1
May 26th, 2004, 08:43 AM
Well thanks.....I will like to try this out as soon as possible the only problem is my computer has a virus. I'm in school right now and they dont have a flash program. However i have some other questions that maybe people here could be of help to. I'm glad I found this site because it's hard to find a good flash/actionscript one.
Anyway, since I can't test to see that you're right (BlackSpirit) I will move on to further questions assuming you are correct. Can you use the mouse release action on a movie clip? I want to make an options bar for the game and I want it so that when click it expands and the border of one of the symbols with in it dissappears. Also if anybody knows of any other ways to do an inventory it may help because I can't test to see if this one is a definite yes.

Robman1
May 26th, 2004, 09:11 AM
BlackSpirit I have a questioin. Suppose this is correct, your actionscript I mean. Could the user acess a screen showing the items added to the inventory? Also once you click this item, how do you make it dissappear so that the movie clip is only in the array, not in the main game? -btw I have figured out just by your script that i am a true noobie.....

Weazol
May 26th, 2004, 05:47 PM
maybe you should start with an easier game just to learn

signifer123
May 26th, 2004, 05:54 PM
http://www.kirupaforum.com/forums/showthread.php?t=54066

there

Robman1
May 27th, 2004, 10:58 PM
BlackSpirit, the code doesnt work but thanks neway.

Robman1
May 28th, 2004, 12:36 AM
ok i think i figured it out by myself. but its not complex or efficient. im using _visible to make the objects visible once the player presses the button. same with the inventory screen....now all i need is that menu

samotboy
May 28th, 2004, 08:08 AM
yeah u could use _visble lol id probaly recommend unloadmovieclip i think if have questions like that u should just read through the action script dictionary in the help section of flash itselfs very useful

Robman1
May 28th, 2004, 08:38 AM
yea i have done that but sometimes the wording is not what im looking for, yet later i find that it was what i needed. i dont think macromedia did very well in their help and tutorial sections. but about the unloadmovieclip, do u need to use loadmovieclip first or can u just movie it onto the screen?

Blackspirit
May 29th, 2004, 03:34 AM
Here, I uploaded an inventory I made up, graphics are non existant, but its the code that matters.
Clicking on the circles add them to the inventory, clicking on the items in the inventory put them to "ground"
Uses attachmovie, so no need to duplicate items from off screen, uses removemovieclip as well. So it'll keep the speed up.

Robman1
May 29th, 2004, 03:41 AM
ok thanks ill check it out

Robman1
May 29th, 2004, 03:46 AM
yea i have been using _visible but my game is starting to slow down in some areas so once i read ur script it may clarify much of what i know

Robman1
May 29th, 2004, 03:48 AM
its not letting me download

Blackspirit
May 29th, 2004, 03:52 AM
wierd, I just downloaded it. Works fine.

Robman1
May 29th, 2004, 03:58 AM
not me it gives me a false download place cant u put it on a site or something? well whatever ill keep trying

Robman1
May 29th, 2004, 03:59 AM
nvm its all cleared up. i didnt know u had to rename it.

Blackspirit
May 29th, 2004, 04:04 AM
rename it? I just rightcliked and saved target as..

Robman1
May 29th, 2004, 04:07 AM
ok im looking at ur script and u have a couple things to explain, sorry. do u have aim? cuz i never understood this i stuff and i just need to learn what this stuff is

Blackspirit
May 29th, 2004, 04:29 AM
nah, dont have aim. got messenger though.

Blackspirit
May 29th, 2004, 04:36 AM
just list the things you dont understand and ill talk you through. I should have put more comments in my code. Commenting is kinda boring :)

Robman1
May 29th, 2004, 10:18 PM
yea ok. i have messenger. ram_junior@msn.com if it shows as a link there is an underscore in there. ok i looked it over today and a lot was cleared up (with help of the macromedia reference) but there are still those things that i have not been cleared up on.

I didnt understand most of these terms:
i
eval
for (i=0; i<inventorySize; i++) {
if (inventory[i] == this.ident) {
inventory[i] = null;
}
}
(im starting to realize this may be easier to explain on msn)
i have other stuff too but it looks like u might not want to explain it all so idk...ill be on msn after 9 eastern time and on tuesday i get comcast so ill be on when ever but with a diff msn.

Blackspirit
June 1st, 2004, 06:20 AM
ok,
the eval evaluates a varialbe, so you can stick it in a target path. So instead of writing this:



_root.b1._x=5;
_root.b2._x=5;
_root.b3._x=5;
_root.b4._x=5;

you can stick this in a for loop, with i being incremented.


_root.eval("b" + i)._x=5;


the next bit is about when you remove an item from your inventory, you wanted it removed from the array as well. To remove it from the array, we make it equal to null.
the "ident" is a variable that the item gets assigned when it is created, this ident also get stored in the array, so we have a record of exactly what items are in our inventory.
So in that case we search through the array using a for loop




for (i=0; i smaller then inventorySize; i++) {<INVENTORYSIZE; p i++) {<>
then we check if the current array value is equal to the item we want to removes ident variable.


if (inventory[i] == this.ident) {

if it is, we remove it from the array, by making the value "null"


inventory[i] = null;
}
}

the we go about removing it phyiscally, by removeing the movieclip.
I'll try and catch you on MSN, but right now its tea time.....mmmmmmmmmm

Robman1
June 1st, 2004, 08:49 AM
lol ok....yea i think it would be best on msn. this has helped my but sometimes its easier in real time. well ill be alot more soon in the event that im getting cable. : )