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

#1 2012-03-19 14:02:53

jedidiahzhu
Scratcher
Registered: 2011-01-16
Posts: 85

Inventory help

I made a drink inventory using a list. The inventory will include water, milk, tea, coffee, and beer in it when I finish it. But right now I've slammed into a mental wall.

In addition to the milk as being a drink, I want it possible for the milk to turn into cheese. Cheese, of course, is not a drink, but a food.

My problem: I don't know how to delete a "milk" item from my list when the item could be ANYWHERE. As far as I know, the list blocks almost all include the need to fill in what number, in this case, the "milk" item is in.

For example, I need something to go in this script:

when [milk into cheese button] clicked
if < [Drinks v] contains [milk]>
delete (1) of [Drinks v]
end
I'll need something different than the "delete 1".

Offline

 

#2 2012-03-19 14:19:16

LS97
Scratcher
Registered: 2009-06-14
Posts: 1000+

Re: Inventory help

what you have is a good start, but I suggest using some kind of method to go through all of the list items and delete them if necessary. For example,

if <[drinks v] contains [milk]>
set [# v] to [1]
repeat until <not <[drinks v] contains [milk]>>
if <(item (#) of [drinks v]) = (milk)>
delete (#) of [drinks v]
end
change [# v] by (1)
end
end
This will go through all the items in the list until there is no more milk!  big_smile

Last edited by LS97 (2012-03-19 14:21:05)

Offline

 

#3 2012-03-19 14:21:00

trinary
Scratcher
Registered: 2012-01-29
Posts: 1000+

Re: Inventory help

Use this.

if <[drinks v] contains [milk]>
set [counter v] to (0)
repeat until <(item (counter) of [drinks v])=[milk]>
change [counter v] by (1)
end
delete (counter) of [drinks v]
else
say [There is no milk in the inventory.] for (2) secs
end
or
if <[drinks v] contains [milk]>
set [counter v] to (0)
repeat until <not <[drinks v] contains [milk]> >
change [counter v] by (1)
if <(item (counter) of [drinks v]) = [milk]>
delete (counter) of [drinks v]
end
end
I have not tested it, but it should work.

Last edited by trinary (2012-03-19 14:25:56)


http://trinary.tk/images/signature_.php

Offline

 

#4 2012-03-20 12:48:46

jedidiahzhu
Scratcher
Registered: 2011-01-16
Posts: 85

Re: Inventory help

trinary wrote:

Use this.

if <[drinks v] contains [milk]>
set [counter v] to (0)
repeat until <(item (counter) of [drinks v])=[milk]>
change [counter v] by (1)
end
delete (counter) of [drinks v]
else
say [There is no milk in the inventory.] for (2) secs
end
or
if <[drinks v] contains [milk]>
set [counter v] to (0)
repeat until <not <[drinks v] contains [milk]> >
change [counter v] by (1)
if <(item (counter) of [drinks v]) = [milk]>
delete (counter) of [drinks v]
end
end
I have not tested it, but it should work.

I think I'll try the first one. The second one looks like it will delete all of the milk, which I don't want to do. Either way, thanks!

Offline

 

#5 2012-03-22 06:41:04

Splodgey
Scratcher
Registered: 2011-04-26
Posts: 500+

Re: Inventory help

LS97 wrote:

what you have is a good start, but I suggest using some kind of method to go through all of the list items and delete them if necessary. For example,

if <[drinks v] contains [milk]>
set [# v] to [1]
repeat until <not <[drinks v] contains [milk]>>
if <(item (#) of [drinks v]) = (milk)>
delete (#) of [drinks v]
end
change [# v] by (1)
end
end
This will go through all the items in the list until there is no more milk!  big_smile

If you want to delete 1 milk:

set [stop v] to [0]
if <[drinks v] contains [milk]>
set [# v] to [1]
repeat until <(stop) = [1]>
if <(item (#) of [drinks v]) = (milk)>
delete (#) of [drinks v]
set [stop v] to [1]
end
change [# v] by (1)
end
end
do other stuff
if you don't need to continue the script just use stop script instead of setting stop.

Last edited by Splodgey (2012-03-28 09:30:18)

Offline

 

#6 2012-03-28 03:47:35

jedidiahzhu
Scratcher
Registered: 2011-01-16
Posts: 85

Re: Inventory help

Thanks everybody!

when gf clicked
go to [computer v
broadcast [open scratch v] and wait
broadcast [start programming v]
think [inventory working!] for (2) secs
say [YAY!!] for (2) secs
forever
broadcast [program]
end

Offline

 

#7 2012-03-28 06:38:59

Unite
Scratcher
Registered: 2012-03-24
Posts: 100+

Re: Inventory help

Well, It looks like your done here! Thanx Splodgy, Trinary, and LS97  big_smile


http://i1156.photobucket.com/albums/p570/bolemis/31023108819264274478797.gif

Offline

 

#8 2012-03-28 09:29:38

Splodgey
Scratcher
Registered: 2011-04-26
Posts: 500+

Re: Inventory help

Unite wrote:

Well, It looks like your done here! Thanx Splodgy, Trinary, and LS97  big_smile

Are you just trying to get your post count up? You really didn't need to post this. And that's Splodgey.

jedidiahzhu wrote:

Thanks everybody!

when gf clicked
go to [computer v]
broadcast [open scratch v] and wait
broadcast [start programming v]
think [inventory working!] for (2) secs
say [YAY!!] for (2) secs
forever
broadcast [program v]

Fixed the scratchblocks.

Last edited by Splodgey (2012-03-28 09:31:44)

Offline

 

#9 2012-03-28 11:06:22

Paddle2See
Scratch Team
Registered: 2007-10-27
Posts: 1000+

Re: Inventory help

Unite wrote:

Well, It looks like your done here! Thanx Splodgy, Trinary, and LS97  big_smile

Thanks for your Report requesting a topic close - however we usually prefer to hear that from the topic owner  smile


http://i39.tinypic.com/2nav6o7.gif

Offline

 

#10 2012-03-29 01:35:18

jedidiahzhu
Scratcher
Registered: 2011-01-16
Posts: 85

Re: Inventory help

Paddle2See wrote:

Unite wrote:

Well, It looks like your done here! Thanx Splodgy, Trinary, and LS97  big_smile

Thanks for your Report requesting a topic close - however we usually prefer to hear that from the topic owner  smile

yes please, I think this forum is no longer needed.

Offline

 

#11 2012-03-29 02:48:59

Splodgey
Scratcher
Registered: 2011-04-26
Posts: 500+

Re: Inventory help

jedidiahzhu wrote:

Paddle2See wrote:

Unite wrote:

Well, It looks like your done here! Thanx Splodgy, Trinary, and LS97  big_smile

Thanks for your Report requesting a topic close - however we usually prefer to hear that from the topic owner  smile

yes please, I think this forum is no longer needed.

I think you need to report the first post...

Offline

 

#12 2012-04-08 02:56:00

Harakou
Community Moderator
Registered: 2009-10-11
Posts: 1000+

Re: Inventory help

Splodgey wrote:

jedidiahzhu wrote:

Paddle2See wrote:


Thanks for your Report requesting a topic close - however we usually prefer to hear that from the topic owner  smile

yes please, I think this forum is no longer needed.

I think you need to report the first post...

Yup, that always helps.  smile  Closing.


http://www.blocks.scratchr.org/API.php?action=random&amp;return=image&amp;link1=http://i.imgur.com/OZn2RD3.png&amp;link2=http://i.imgur.com/duzaGTB.png&amp;link3=http://i.imgur.com/CrDGvvZ.png&amp;link4=http://i.imgur.com/POEpQyZ.png&amp;link5=http://i.imgur.com/ZKJF8ac.png

Offline

 

Board footer