Discuss Scratch

Snowjo88
Scratcher
11 posts

Removing an item inside a list with a specific name/value

Im listing all the different values of a sprite clone in a list, and when the clone dies, I want it to remove all the values from the list that previously belonged to the clone. For example if I add the speed value to the list, I tried putting it like this:

When it dies - delete (Speed variable) of list

Any help is appreciated

Last edited by Snowjo88 (June 16, 2019 14:59:46)

codeman1044
Scratcher
1000+ posts

Removing an item inside a list with a specific name/value

Try making a tag for the items of the list using local variables (for this sprite only) that change for each clone so that you can use sort of an ID variable and check that with the lists. I would recommend using letters for the ID variable. I'll explain what I mean.
For an explanation on local variables, see here.
I don't know what your circumstances are, so I'll make my own. Let's say you're adding 3 stats to a list: speed, damage, and defense. All of those would be local variables since they would change per clone. When you added them to the list, it would look something like this:
 add (join (speed) (ID)) to [stats v]
add (join (defense) (ID)) to [stats v]
add (join (damage) (ID)) to [stats v]
When you want to delete them, you would run this script:
set [counter v] to (1)//this must be a local variable
repeat (length of [stats v])//see note 1
if <(letter (length of (item (counter) of [stats v])) of (item (counter) of [stats v]))=(ID)> then
delete (item (counter) of [stats v]) of [stats v]
end
change [counter v] by (1)
end
delete this clone
1. The reason for the (length of) block is just to check the last letter. If the length of the string is 5 long, it will check letter 5.

I hope you can see why you would use letters for the ID variable. It would cause an issue otherwise.
If you have more or fewer stats, you would just change how many things you add to the stats list.
Hopefully this helps! Let me know if something doesn't work or you need something else.

Last edited by codeman1044 (June 16, 2019 15:13:33)

Powered by DjangoBB