This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2010-06-04 14:21:07

adiguy17
Scratcher
Registered: 2010-05-04
Posts: 17

Inventory

I was making this one game where you can buy items and you can use use the items later. I wanted to know how to make an inventory to keep all of the items in.

Offline

 

#2 2010-06-04 15:44:39

coolstuff
Community Moderator
Registered: 2008-03-06
Posts: 1000+

Re: Inventory

Well, there are two ways to do this. If you have only a few items that you'll need to buy many of, I think the best way to do that is to use variables. Make a variable for each item you can buy, call it "item name inventory" or something along those lines, depending on the name of your item. Then, when you buy one of those items, make the variable go up by one, and when you use one, make it go down by one.

The other way is with lists, which is more for if you're going to have many items which are mostly different from eachother. When you get an item, add it to the list, and when you lose or use one, remove it from the list - I can write up more details on how you can do that if you want.

If you want to visually display the items in the inventory, feel free to reply to this and I'll go more in-depth on it.

Offline

 

#3 2010-06-04 18:23:15

adiguy17
Scratcher
Registered: 2010-05-04
Posts: 17

Re: Inventory

Yeah, I need the item to actually be seen. For example, if I have a sword I want the character to hold the sword when he buys it. Thank you for the reply!

Offline

 

#4 2010-06-04 18:40:58

coolstuff
Community Moderator
Registered: 2008-03-06
Posts: 1000+

Re: Inventory

Well, if you want to character to hold a sword once he buys it, you have two options; quite similar to those I described above.

Use a variable to decide whether he has a sword or not. If the variable says he has a sword, make him switch to a costume where he is holding a sword, or make a sprite go to his hand using a script similar to this one:

Code:

go to x: (([x position] of [me]) + (15 - or any number which can offset the position to go to his hand)) y: (([y position] of [me]) + (15 - or any number which can offset the position to go to his hand))

Or you can use a list, which contains every item in his inventory. Using the <[list] contains [thing] > block, you can determine whether or not the thing is in his inventory, and make the sprite appear or disappear accordingly.

If you need any more help, feel free to ask!

Offline

 

#5 2010-06-06 17:17:11

adiguy17
Scratcher
Registered: 2010-05-04
Posts: 17

Re: Inventory

Thank you very much!!☺☻☺☻☺

Offline

 

#6 2010-06-06 18:22:17

coolstuff
Community Moderator
Registered: 2008-03-06
Posts: 1000+

Re: Inventory

No problem! Happy to help  big_smile

Offline

 

Board footer