Discuss Scratch

fivehead
Scratcher
1000+ posts

How do you remove a specific item from a list?

I'm basically doing a rpg-ish game and a lot of choices will be text-based.

This is what I have as of now:

when this sprite clicked
ask [Item?] and wait
if <[items v] contains [ (answer)]> then
say [Success!] for (2) secs

end

Of course the success part is just for testing purposes. But what I'm trying to do is remove that item after it's used. Is there any way to do this? It seems like there would be because it's so simple, but you never know.

I've tried:

delete ((answer) v) of [Items  v]

I've tried using this as part of the previous script, but it did not appear to work.

Last edited by fivehead (March 10, 2016 04:02:41)

DanloVorje
Scratcher
100+ posts

How do you remove a specific item from a list?

The “delete () of (list v)” block can only take a number as an input (aka the position of the item you want to delete). In order to delete an item in a list containing a specific string, you'll need to use an iterative loop.

The basic structure would be something like this:
set [i v] to [1]
repeat until <<(item (i) of [list v]) = [thing you want to delete]> or <(i) > (length of [list v])> >
change [i v] by (1)
end
delete (i) of [list v]

Note that this would delete only the first instance of the thing you want to delete, not all instances of it.

Hope this helps!

–Danlo

What I'm working on right now: Isle of Dolor
fivehead
Scratcher
1000+ posts

How do you remove a specific item from a list?

DanloVorje wrote:

The “delete () of (list v)” block can only take a number as an input (aka the position of the item you want to delete). In order to delete an item in a list containing a specific string, you'll need to use an iterative loop.

The basic structure would be something like this:
set [i v] to [1]
repeat until <<(item (i) of [list v]) = [thing you want to delete]> or <(i) > (length of [list v])> >
change [i v] by (1)
end
delete (i) of [list v]

Note that this would delete only the first instance of the thing you want to delete, not all instances of it.

Hope this helps!

–Danlo
Is “i” a certain variable I should be using, or is that just an example? Thanks for the help!
deck26
Scratcher
1000+ posts

How do you remove a specific item from a list?

fivehead wrote:

DanloVorje wrote:

The “delete () of (list v)” block can only take a number as an input (aka the position of the item you want to delete). In order to delete an item in a list containing a specific string, you'll need to use an iterative loop.

The basic structure would be something like this:
set [i v] to [1]
repeat until <<(item (i) of [list v]) = [thing you want to delete]> or <(i) > (length of [list v])> >
change [i v] by (1)
end
delete (i) of [list v]

Note that this would delete only the first instance of the thing you want to delete, not all instances of it.

Hope this helps!

–Danlo
Is “i” a certain variable I should be using, or is that just an example? Thanks for the help!
There is rarely (if ever) any need for a variable to have a particular name. You can call it ‘i’ or ‘index’ or ‘loop control’ or ‘this is a stupid name for a variable’.
fivehead
Scratcher
1000+ posts

How do you remove a specific item from a list?

deck26 wrote:

fivehead wrote:

DanloVorje wrote:

The “delete () of (list v)” block can only take a number as an input (aka the position of the item you want to delete). In order to delete an item in a list containing a specific string, you'll need to use an iterative loop.

The basic structure would be something like this:
set [i v] to [1]
repeat until <<(item (i) of [list v]) = [thing you want to delete]> or <(i) > (length of [list v])> >
change [i v] by (1)
end
delete (i) of [list v]

Note that this would delete only the first instance of the thing you want to delete, not all instances of it.

Hope this helps!

–Danlo
Is “i” a certain variable I should be using, or is that just an example? Thanks for the help!
There is rarely (if ever) any need for a variable to have a particular name. You can call it ‘i’ or ‘index’ or ‘loop control’ or ‘this is a stupid name for a variable’.
I knew that, but I was just asking if I needed a variable also coordinated with something else. Either way, thanks for the help!
KEL5isGod
Scratcher
27 posts

How do you remove a specific item from a list?

fivehead wrote:

deck26 wrote:

fivehead wrote:

DanloVorje wrote:

The “delete () of (list v)” block can only take a number as an input (aka the position of the item you want to delete). In order to delete an item in a list containing a specific string, you'll need to use an iterative loop.

The basic structure would be something like this:
set [i v] to [1]
repeat until <<(item (i) of [list v]) = [thing you want to delete]> or <(i) > (length of [list v])> >
change [i v] by (1)
end
delete (i) of [list v]

Note that this would delete only the first instance of the thing you want to delete, not all instances of it.

Hope this helps!

–Danlo
Is “i” a certain variable I should be using, or is that just an example? Thanks for the help!
There is rarely (if ever) any need for a variable to have a particular name. You can call it ‘i’ or ‘index’ or ‘loop control’ or ‘this is a stupid name for a variable’.
I knew that, but I was just asking if I needed a variable also coordinated with something else. Either way, thanks for the help!
The variable can be named anything really, you can even name it
(seventeen seventy five mate)

ask [] and wait::looks
Wait…
deck26
Scratcher
1000+ posts

How do you remove a specific item from a list?

fivehead wrote:

deck26 wrote:

fivehead wrote:

DanloVorje wrote:

The “delete () of (list v)” block can only take a number as an input (aka the position of the item you want to delete). In order to delete an item in a list containing a specific string, you'll need to use an iterative loop.

The basic structure would be something like this:
set [i v] to [1]
repeat until <<(item (i) of [list v]) = [thing you want to delete]> or <(i) > (length of [list v])> >
change [i v] by (1)
end
delete (i) of [list v]

Note that this would delete only the first instance of the thing you want to delete, not all instances of it.

Hope this helps!

–Danlo
Is “i” a certain variable I should be using, or is that just an example? Thanks for the help!
There is rarely (if ever) any need for a variable to have a particular name. You can call it ‘i’ or ‘index’ or ‘loop control’ or ‘this is a stupid name for a variable’.
I knew that, but I was just asking if I needed a variable also coordinated with something else. Either way, thanks for the help!
That script is complete so the variable doesn't have to coordinate with anything else. Obviously you have to be careful that other scripts aren't trying to use the variable at the same time.
fivehead
Scratcher
1000+ posts

How do you remove a specific item from a list?

deck26 wrote:

fivehead wrote:

deck26 wrote:

fivehead wrote:

DanloVorje wrote:

The “delete () of (list v)” block can only take a number as an input (aka the position of the item you want to delete). In order to delete an item in a list containing a specific string, you'll need to use an iterative loop.

The basic structure would be something like this:
set [i v] to [1]
repeat until <<(item (i) of [list v]) = [thing you want to delete]> or <(i) > (length of [list v])> >
change [i v] by (1)
end
delete (i) of [list v]

Note that this would delete only the first instance of the thing you want to delete, not all instances of it.

Hope this helps!

–Danlo
Is “i” a certain variable I should be using, or is that just an example? Thanks for the help!
There is rarely (if ever) any need for a variable to have a particular name. You can call it ‘i’ or ‘index’ or ‘loop control’ or ‘this is a stupid name for a variable’.
I knew that, but I was just asking if I needed a variable also coordinated with something else. Either way, thanks for the help!
That script is complete so the variable doesn't have to coordinate with anything else. Obviously you have to be careful that other scripts aren't trying to use the variable at the same time.
Right, thank you!
GreenExplosion08
Scratcher
31 posts

How do you remove a specific item from a list?

I'm making a Neko Atsume game and I need to be able to make it so you can delete your file and after a bunch of tries, that script really worked! Thanks! I wrote my script in a message(P.S. I named “i” as “Name”):
                                                                                          when I receive [delete file]
set [Name] to [1]
repeat until <(item (Name) of [Files] :: list) = (username)>
change [Name] by (1)
end
delete (Name) of [Files]
Deck26 wrote:
Fivehead wrote:
Deck26 wrote:
Fivehead wrote:
Danlo Vorje wrote:
The “delete () of (list v)” block can only take a number as an input (aka the position of the item you want to delete). In order to delete an item in a list containing a specific string, you'll need to use an iterative loop.

The basic structure would be something like this:
                                                                                          set [i] to [1]
repeat until <(item (i) of [list] :: list) = (thing you want to delete)>
change [i] by (1)
end
delete (i) of [list]
Note that this would delete only the first instance of the thing you want to delete, not all instances of it.

Hope this helps!

–Danlo
Is “i” a certain variable I should be using, or is that just an example? Thanks for the help!
There is rarely (if ever) any need for a variable to have a particular name. You can call it ‘i’ or ‘index’ or ‘loop control’ or ‘this is a stupid name for a variable’.
I knew that, but I was just asking if I needed a variable also coordinated with something else. Either way, thanks for the help!
That script is complete so the variable doesn't have to coordinate with anything else. Obviously you have to be careful that other scripts aren't trying to use the variable at the same time.

Last edited by GreenExplosion08 (Oct. 19, 2016 23:44:58)

lx_monster
Scratcher
36 posts

How do you remove a specific item from a list?

fivehead wrote:

I'm basically doing a rpg-ish game and a lot of choices will be text-based.

This is what I have as of now:

when this sprite clicked
ask [Item?] and wait
if <[items v] contains [ (answer)]> then
say [Success!] for (2) secs

end

Of course the success part is just for testing purposes. But what I'm trying to do is remove that item after it's used. Is there any way to do this? It seems like there would be because it's so simple, but you never know.

I've tried:

delete ((answer) v) of [Items  v]

I've tried using this as part of the previous script, but it did not appear to work.
?


if <(what i'm doing) = [lying in bed]> then
broadcast [think about possibilities on scratch]
end
Charles12310
Scratcher
1000+ posts

How do you remove a specific item from a list?

lx_monster wrote:

fivehead wrote:

I'm basically doing a rpg-ish game and a lot of choices will be text-based.

This is what I have as of now:

when this sprite clicked
ask [Item?] and wait
if <[items v] contains [ (answer)]> then
say [Success!] for (2) secs

end

Of course the success part is just for testing purposes. But what I'm trying to do is remove that item after it's used. Is there any way to do this? It seems like there would be because it's so simple, but you never know.

I've tried:

delete ((answer) v) of [Items  v]

I've tried using this as part of the previous script, but it did not appear to work.
?
Please do not necropost. If you have more questions, please make a new topic.


A few internet communication companies want to corrupt the internet by getting rid of net neutrality. Stop Them!

Powered by DjangoBB