PDA

View Full Version : Help on Inventory



superNoobice
February 17th, 2005, 10:51 AM
Hi. I'm working on this flash game RPG and all seems well when i finally decidedd to get the inventory goin. but no to avail, i've spend 2 nights trying to figure out how to make this thing works.

Can anyone tell me how to fix this? I want my guy to buy an item then it will be added to his inventory. If he has already one, it will add to the quantity. then if he wants to equip it, and if the item has only 1 left, he may equip it but it will disappear on his list but appear on the Equip screen. If he unequips it, it will return to inventory and disappear on the Equip screen. hmmm....

You can have a look at my work. :) feel free to comment on anything.

superNoobice
February 17th, 2005, 10:52 AM
oh. i forgot, to anyone who wants to try my game. 'a' to enter a door and portals and 'i' for inventory.

Lord Rahl
February 17th, 2005, 11:00 AM
I can't check it out at the moment, But I will set up and explain as much as I can when I get home. Providing my computer stops its 2-3 day error routine. (Along with my server and Internet. Sheesh, everythings messing up all of a sudden.) But the answer to this bassicly lies with MC's and more framework, + textfields and Variables. Long work to make things great.

superNoobice
February 17th, 2005, 11:04 AM
I think also on data management. Consider also that data in inventory may change depending on what the player will do (use item, pick new item)... I hope you can explain this to me. im really lost and its my 1st try to make a game.

Lord Rahl
February 17th, 2005, 11:13 AM
I think also on data management. Consider also that data in inventory may change depending on what the player will do (use item, pick new item)... I hope you can explain this to me. im really lost and its my 1st try to make a game.
I'll explain as much as I can in a few hours hopefully.

superNoobice
February 17th, 2005, 10:29 PM
*bump

Lord Rahl
February 18th, 2005, 09:31 PM
Ok, I am finally back from my disaster weeks. I'll work on something to show you the layout. Though I have never done a inventory system before, I have watched a friend do it and it should not be to hard. If worse comes to worse I can have him hook you up if he still has flash.;)

superNoobice
February 19th, 2005, 09:07 AM
thanks man. been lurking on other forums to find what i need to know. no luck still. Is it really that hard? or maybe i think too much for my inventory system. Besides, i never come across a flash game RPG with complex inventory system such as what i am thinking now.

Lord Rahl
February 19th, 2005, 12:46 PM
Is it really that hard? or maybe i think too much for my inventory system. Besides, i never come across a flash game RPG with complex inventory system such as what i am thinking now.
Well, its not that it is too complicated. I think most people just don't want to take the time to fully make a inventory system that is detailed. But time is what makes great games.

bombsledder
February 19th, 2005, 01:55 PM
maybe somethinglike this



item1equiped=false
item1quantity=0
item1have=false


and so on for eachitem now to make it add u could do something like



if(item1quanity==0){
item1have=false
}

if(item1have){
//add the item to inventory
}

if(item1quanity>0){
_root.yourdynamictext=itemquanity++
}


something like that maybe?

Lord Rahl
February 19th, 2005, 02:35 PM
Thats kinda like what I was thinking, though a bit different.:hugegrin:

bombsledder
February 19th, 2005, 02:47 PM
o well im working on it right now then im gonna post the .fla of it so he can see or anyone else wnats to see :P :P :P

bombsledder
February 19th, 2005, 03:30 PM
actually i cant get minet work lol if someone wants too look at it an maybe fix it ill post it

Copes
February 19th, 2005, 04:17 PM
you know, i read the posts on here and i look at the code people supply. and i cant help feel im doing everything the "noobie" way lol, but hey aslong as it works right? ;)

Basically the way milo's inventory works is each item has a set mc inside the main inventory mc. this "item" mc has a alpha property of 0. which even tho we use visible = true/false; we found if we just used the visible state when you opened the inventory the items would "flash" for a second. before going invisible.

on the script layer there is a //inventory section. which we have things like: inv_health, inv_cure etc. and on pick up'aple items we simply have _root.inv_health += 1;

the code on the main mc is:


onClipEvent (enterFrame) {
if (_root.inv_health>0) {
this.item_mc._visible = true;
this.item_mc._alpha = 100;
} else if (_root.inv_health == 0) {
this.item_mc._visible = false;
this.item_mc._alpha = 0;
}

inside the "item" mc which is set to 0 alpha. there is the graphic of whichever item it is you want, and a small dynamic text box which look at _root.inv_"whichever item" to display the number of items you have :)

Im not sure if this is the "proper" way to do it, but it works to a point aslong as your happy with having your items in set positions in the inventory. anyway i hope that helps mate ;)

Copes

Lord Rahl
February 19th, 2005, 07:45 PM
I'll take a look at your Fla bombsledder and Copes, its better to do things your way if its easy for you than anothers way that is challenging. And Thanks, your script helped.:beer:

bombsledder
February 19th, 2005, 07:49 PM
ya i think i do it the noobie way lol i dont use functions or anything just basic because that is the way i learned anyother way is wierd...and confuses me.... :book: but hey ya look at my script i might decide to work on a rpg that loads and saves from a database and has a big map u know :P

Lord Rahl
February 19th, 2005, 10:42 PM
Yea, I am sorta the same way. At least some times. I am trying to learn the advanced stuff, but I still like doing things in a noobie way. Mainly because I am used to it and I can do more that way than any other way.=)

superNoobice
February 20th, 2005, 12:34 AM
isnt copes code limited to only the same type of items on each slot? i was thinking of making mine dynamic. I mean, if its a free slot any item can go in. not just hiding the mc when you have no item left (of 1 kind).

Copes
February 20th, 2005, 07:38 AM
it is yes :P i did say it was. how would u go about making it all dynamic? we kinda just went for this method to save some time really.

superNoobice
February 20th, 2005, 08:17 AM
:) ummm.. well i was thinking since i was making an RPG i might as well make it dynamic so i can add as many items as i want and the slots in the inventory also increases automatically. nice game BTW :)

Copes
February 20th, 2005, 09:35 AM
hmm i think i have an idea how to do a more dynamic inventory :) ill have ago and post how well it doesnt work in a few hours lol :)

superNoobice
February 20th, 2005, 10:58 AM
my mind's messed up. i think i'll take a break maybe a week. then try to mess with it some more. but for now, ill try to make something new. maybe a platformer, i dunno... :)

bombsledder
February 20th, 2005, 11:39 AM
thats sort of what i was trying to say make it dynamic....but i want it to be easier and check if it has an item id of something for example

tables in an rpg are usually pushable (at least the ones i play) so it would have an itemid of like 50

itemid=50


then if i try dragging it to a slot that it checks if it has an itemid of 50 and if it does it will send it back to its old x and y but i need to know if there is a way to that if anything touches the slot it will count as a hitTest

Lord Rahl
February 21st, 2005, 07:00 PM
Alright, rather than making a large inventory system I made a small one. This flash shows you how to make a inventory system that increases as buy items or sell. You can also increase you items quanity through hitTest as well with a similar script as this. This is very basic. If you have any questoins about how to do this but in a different way then let me know. ;)
Opps had to edi this. Forgot to post file.

superNoobice
February 21st, 2005, 07:50 PM
can't open it. is it in MX 2004?

bombsledder
February 21st, 2005, 08:46 PM
ya this is pretty basic lol i made something like that when i first learned flash

i was trying to make something where u drag and drop stuff in

Lord Rahl
February 22nd, 2005, 01:45 AM
Yes, it is MX 2004. If you still can't post it i'll repost it. But this is a basic layout for a inventory + shows how to do adding and subtracting var with a shop menu. You can easily modify it to add with hitTest, and more. As for drag and drop inventorys. Well I am still working on that. I had it almost done but found major errors and still currently working on it.

superNoobice
February 22nd, 2005, 02:19 AM
can you explain it to me here? I cant view it. you see, I'm on MX and it says, "Unexpected file format".

Lord Rahl
February 22nd, 2005, 03:16 AM
Understandable. I'll explain as best I can. Let me know if oyu have any questions after. And one thing, NOTE: this is only a brief and basic explanation on a inventory system. The system is simple and may be or not be what you want, but it is the same general idea and can be bent to your ways. First off, we need to asign variables. For example: Herb = 0 or Potion = 0. This will go in your 1st frame that is loaded so the player can't see it. This dos exactly what it says. You have 0 herbs and such. Next you need a text area to place in the item name and quanity. Dynamic text boxs work well, then you must asign a Var name. So to keep it simple we should just name it Potion or Herb. Name it the same name as the corresponding variables. Then you need to make it update with the variables. But first make sure you enter the script to show the quanity. So in the frame with the dynamic text box insert the following action(s).

herb = Herb herb being the text box and Herb being the quanity. Once this is done, we make a script or a btn to open the inventory area. This script should also imput the latest update to the variables/quanity. And then the script you use to close the inventory system must include a script to update the vairiables. For example, if the character buys a herb, it takes the quanity in the current text box and replaces the total quanity for the next text box that is shown. Get it? I'll end this here and wait for confirmation that you understand up to this point before moving on. And I have attached a Swf to show you this. It is the same as the Fla, but hopefully you can open this.

superNoobice
February 22nd, 2005, 03:59 AM
Yeah. thanks. Understood. Is it the increment on BUY button that will make you buy the potion. like this?

on(release){
_root.herb++;
}

and on sell we use
on(release){
_root.herb--;
}

My question, :) can i make my listing of current items be empty? I mean, like if i started the game, i dont have any items on my inventory right? except for some potions that could aid me. What if for example if happen to pick up a sword and the sword's name is "Ultima Weapon". At first my inventory must not have the said sword but will appear on the inventory only once i picked it up. My inventory list should look like this:
___________
INVENTORY |
-----------------------------------
Potions: 3
Herb: 3
-----------------------------------

once i picked the sword up or buy the sword i want my inventory to look like this
_____________
INVENTORY |
-------------------------------------
Potion: 3
Herb: 3
Ultima Weapon: 1
-------------------------------------

That's my problem is... :(
And also, if i want to equip my Ultima Weapon like this

________________
EQUIPMENTS |
------------------
Hand: |
Upper: |
Body: |
Lower: |
------------------
________________
INVENTORY |
------------------
Potion: 3 |
Herb: 3 |
Ultima Weapon: 1 |
------------------

And then i equip the sword:
________________
EQUIPMENTS |
------------------
Hand: Ultima Weapon |
Upper: |
Body: |
Lower: |
---------------------
________________
INVENTORY |
------------------
Potion: 3 |
Herb: 3 |
------------------

Peace :)

Marz
February 22nd, 2005, 05:21 AM
     The inventory system can be one of the biggest items you have to work on in your game. I would personally suggest making the items an object of its own and then set it up so that parameters can be set up.

     Much like the way I created my Door Object system in my rpg game. :book: It allows you to create obects that can be cycled through very easily and set up to whether the item is usable, movable, burnable, edible, poisonous, or whatever properties you want.

I'll have more info for you on this topic later. It's time for some much needed sleep.

superNoobice
February 22nd, 2005, 07:10 AM
@marz
thanks marz. I tried making it an object. One question, can i store objects in an array?

@lord Rahl
Thanks to you too, you've been a great help.! :)

Marz
February 22nd, 2005, 04:04 PM
Yes you can... But it's not really worth it.

Check this out:

Say you make an Inventory MovieClip... And all your items get stored ino that clip.. If you wanted to look up a particular one :

_root.Inventory["item"+i] or however you name them

Or you could

for(var i in _root.Inventory)

will cycle through all the items in Inventory made.

Lord Rahl
February 22nd, 2005, 06:05 PM
Well said Marz.:thumb:
Btw, you should consider joining Seifertims development team for Worlds. You could be a considerable help.

mixedtrigeno
February 22nd, 2005, 07:21 PM
The inventory system can be one of the biggest items you have to work on in your game. I would personally suggest making the items an object of its own and then set it up so that parameters can be set up.

Much like the way I created my Door Object system in my rpg game. :book: It allows you to create obects that can be cycled through very easily and set up to whether the item is usable, movable, burnable, edible, poisonous, or whatever properties you want.

I'll have more info for you on this topic later. It's time for some much needed sleep.
marz are all those properties able to do in an art base rpg game? and are you going to implement that into the tutorials that you are making? sorry if you already did i havent look at your thead yet...

Marz
February 22nd, 2005, 07:31 PM
art based or tile based... the same inventory system can be used for both... I'm in the process of creating a couple of tutorials right now. I wihs I had my own folder to place all these tutorials in... *lol*...

But anyways, yeah... I'm working on an inventory system for you guys to check out... buying, selling, moving, equipping and the such... :)

After I finish the next ai piece (describing the ai I made last time that is)

superNoobice
February 22nd, 2005, 08:01 PM
art based or tile based... the same inventory system can be used for both... I'm in the process of creating a couple of tutorials right now. I wihs I had my own folder to place all these tutorials in... *lol*...

But anyways, yeah... I'm working on an inventory system for you guys to check out... buying, selling, moving, equipping and the such...

After I finish the next ai piece (describing the ai I made last time that is)

That would be great!!! I'll be looking forward to that.


Yes you can... But it's not really worth it.

Check this out:

Say you make an Inventory MovieClip... And all your items get stored ino that clip.. If you wanted to look up a particular one :

_root.Inventory["item"+i] or however you name them

Or you could

for(var i in _root.Inventory)

will cycle through all the items in Inventory made.

I tried this one. hmmm. There must be some mistake somewhere... I'll gonna give it a shot again. Cycling through the inventory gets me confused most of the time.

Marz
February 22nd, 2005, 11:19 PM
Allright... Well for you guys. I created a small .swf file that explains what I mean about creating an object.



function Ball(positionX, positionY)
{
this.xPosition = positionX;
this.yPosition = positionY;

this.image = _root.main_ball.duplicateMovieClip("ball"+_root.uID, _root.uID);
this.image._x = this.xPosition;
this.image._y = this.yPosition;

// trace("Ball Number "+numBalls+": ("+positionX+", "+positionY+")");

this.getXposition = function() { return this.xPosition; }
this.getYposition = function() { return this.yPosition; }
this.setXposition = function(xLocation)
{
this.xPosition = xLocation;
this.image._x = xLocation;
}
this.setYposition = function(yLocation)
{
this.yPosition = yLocation;
this.image._y = yLocation;
}

this.addProperty("_ballx", this.getXposition, this.setXposition);
this.addProperty("_bally", this.getYposition, this.setYposition);
}


This is an object I created for this small experiment... I wanted to test it to see how many balls I could have moving onScreen before it starts to lag up... This is a pretty hefty function / object to create for every ball... And I was surprised to see that could have In upwards of over 75-80 on the mac I use! That's pretty impressive... So now you guys should understand how powerful objects can be. :)

Marz
February 22nd, 2005, 11:21 PM
Ohh... And btw supernoobice :



for(var i in _root.Inventory)
{
_root.Inventory[i]. whatever;
}

superNoobice
February 23rd, 2005, 12:58 AM
thanks.. but what does that "in" do?

for(var i in <----?

Marz
February 23rd, 2005, 03:43 AM
It's just like a pointer... It says... Take everything IN _root.Inventory and place it IN var i or whatever variable you want to say.

superNoobice
February 23rd, 2005, 04:58 AM
i see... after 2 mins...

wow. this in thing is good. Now its easier to cycle through objects inside mc...
:grin:

Thanks.

Marz
February 23rd, 2005, 03:31 PM
for in loops work for arrays too man ;)

superNoobice
February 23rd, 2005, 07:25 PM
i didnt know about this in loops till you introduce it to me. :)

Marz
February 23rd, 2005, 07:57 PM
There are alot of things out there that people don't know about... switch statements, while loops, do. while loops, for in and for loops. Alot of stuff man. Listeners are another segment... And a couple of other things here and there... ALOT about functions... Which can be extremely powerful if used right... I could go on for a couple hundred sentences.

d1srupta
June 3rd, 2005, 12:27 AM
hey, the way supernoobice wanted his inventory, thats exactly what i need, anyone willing to help? I wouldnt know how to to start lol