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

#1 2010-06-09 14:25:35

dunvegan5
Scratcher
Registered: 2009-12-04
Posts: 51

Deleting Certain Item of List

I am making this game where to set a fire, you need logs in your inventory, and some flint. You lose the logs once you build the fire. What I want to say is:
If inventory contains logs and flint and key f pressed:
broadcast Fire
delete item "Logs" of inventory



I can't get it to delete anything but all, or top, or item #_. What if logs are item 2 or item 673? How do you get Scratch to delete Logs, no matter where it is on the list?


Please support Snakehead Island 2!
Snakehead Island 2 is coming along 763% better than Snakehead Island 1!

Offline

 

#2 2010-06-09 14:35:40

colorfusion
Scratcher
Registered: 2009-10-03
Posts: 500+

Re: Deleting Certain Item of List

You will need to do it a long way around, make a variable called log# then do this script

[When f key pressed]
[If <List contains logs> and <List contains flint>]
[] [Set [Log#] to 0]
[] [Repeat until <[Logs] = (item(log#) of list)>
[] [] [Change [log#] by 1]
[] [The repeat block stops here]
[] [Delete (log#) of [list]]
[] [Broadcast [fire]]
[The repeat block ends here]

Offline

 

#3 2010-06-09 14:38:05

Wolfie1996
Retired Community Moderator
Registered: 2009-07-08
Posts: 1000+

Re: Deleting Certain Item of List

You can click in the little white text box thingy, and type your number in there - it's much simpler than using variables (if items' positions in the list are fixed)  smile


"...Jargon - the practice of never calling a spade a spade, when you might instead call it a manual earth-restructing implement..." - Bill Bryson, Mother Tongue

Offline

 

#4 2010-06-09 14:39:37

johnnydean1
Scratcher
Registered: 2010-02-12
Posts: 1000+

Re: Deleting Certain Item of List

This is hard to explain, but here goes:

You have 2 variables
Temp.1
Temp.2

you do a code like this:

set Temp.1 to 0
set Temp.2 to 0
repeat (length of (ITEMS LIST))
| change Temp.1 by 1
| if <(Item (Temp.1) of (ITEMS LIST)) = logs>
| | set  Temp.2 to (Temp.1)
|__________________________________________
___________________________________________

At the end of this Temp.2 will hold the positon of logs in the list, so then use

(delete item (Temp.2) of (ITEMS LIST))

and if Temp.2 = 0 then you have none in the list!


You can now reach me on Twitter @johnnydean1_

Offline

 

#5 2010-06-18 23:09:24

waveOSBeta
Scratcher
Registered: 2009-12-08
Posts: 1000+

Re: Deleting Certain Item of List

Ahem.

[delete item (2) from list [inventory]]


http://internetometer.com/image/10202.png]
New signature coming soon!  smile

Offline

 

#6 2010-06-19 03:35:18

johnnydean1
Scratcher
Registered: 2010-02-12
Posts: 1000+

Re: Deleting Certain Item of List

But what if logs are in a diffrent place.


You can now reach me on Twitter @johnnydean1_

Offline

 

Board footer