Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » How do you remove a specific item from a list?
- 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:
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:
I've tried using this as part of the previous script, but it did not appear to work.
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:
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
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?
Is “i” a certain variable I should be using, or is that just an example? Thanks for the help! 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
- deck26
- Scratcher
1000+ posts
How do you remove a specific item from a list?
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’.Is “i” a certain variable I should be using, or is that just an example? Thanks for the help! 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
- fivehead
- Scratcher
1000+ posts
How do you remove a specific item from a list?
I knew that, but I was just asking if I needed a variable also coordinated with something else. Either way, 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’.Is “i” a certain variable I should be using, or is that just an example? Thanks for the help! 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
- KEL5isGod
- Scratcher
27 posts
How do you remove a specific item from a list?
The variable can be named anything really, you can even name itI knew that, but I was just asking if I needed a variable also coordinated with something else. Either way, 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’.Is “i” a certain variable I should be using, or is that just an example? Thanks for the help! 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
(seventeen seventy five mate)
ask [] and wait::looksWait…
- deck26
- Scratcher
1000+ posts
How do you remove a specific item from a list?
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.I knew that, but I was just asking if I needed a variable also coordinated with something else. Either way, 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’.Is “i” a certain variable I should be using, or is that just an example? Thanks for the help! 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
- fivehead
- Scratcher
1000+ posts
How do you remove a specific item from a list?
Right, thank you!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.I knew that, but I was just asking if I needed a variable also coordinated with something else. Either way, 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’.Is “i” a certain variable I should be using, or is that just an example? Thanks for the help! 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
- 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: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.Deck26 wrote:I knew that, but I was just asking if I needed a variable also coordinated with something else. Either way, thanks for the help!Fivehead wrote: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’.Danlo Vorje wrote:Is “i” a certain variable I should be using, or is that just an example? Thanks for the help!
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]Note that this would delete only the first instance of the thing you want to delete, not all instances of it.
repeat until <(item (i) of [list] :: list) = (thing you want to delete)>
change [i] by (1)
end
delete (i) of [list]
Hope this helps!
–Danlo
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?
? 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?
Please do not necropost. If you have more questions, please make a new topic.? 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.
A few internet communication companies want to corrupt the internet by getting rid of net neutrality. Stop Them!
- Discussion Forums
- » Help with Scripts
- » How do you remove a specific item from a list?