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

#1 2011-03-27 07:02:25

quasar13
New Scratcher
Registered: 2011-03-07
Posts: 2

How do I remove a particular item from a list?

Hi

Lets say I am making a space invaders type game called fruit invaders.  I am being attacked by a banana, an orange, an apple, a cherry and a pear.  How do I remove a particular item from the list of fruit? I can't easily use the

delete (1/last/all) of  FRUIT

option because the fruit positions change as fruit are shot down at random.

There doesn't seem to be an easy way to delete, say, the banana given that I do not know its position in the list.

I basically want to

delete banana of Fruit

Any advice would be appreciated.

Offline

 

#2 2011-03-27 07:17:39

Clank23
Scratcher
Registered: 2011-03-01
Posts: 1000+

Re: How do I remove a particular item from a list?

Put a lot of ifs for if ALL the fruit if in, then depending on which if it has reached put a delete all of fruit and add all the fruit it picked up as in in apart from bannana,
Sorry if this is complicated but i think it is the only way.


http://img846.imageshack.us/img846/4333/signaturely.png

Offline

 

#3 2011-03-27 07:29:46

quasar13
New Scratcher
Registered: 2011-03-07
Posts: 2

Re: How do I remove a particular item from a list?

Thanks Clank23

I was thinking of doing something like that.

I found the following code on the forum.
hmnwilson wrote something like this

set [listchecker] to (1)
repeat until <(item (listchecker) of [FRUIT])) = [banana]>
  change [listchecker] by (1)
[end of loop]
delete item (listchecker) of [FRUIT]


It uses a loop to determine which position the fruit is in then removes the object in that position.  Just tried it and it works.

Offline

 

Board footer