Discuss Scratch

monia5305
New Scratcher
5 posts

Script to delete letters from a word enetered by a user.

Hi all. I would like to create a script to delete the letters (from the list I created) from the word entered by a user and display it as a new word (stored as variable “new_word”)

I'm struggling to understand how to get there as I've tried multiple scripts and I am not getting anywhere. I hope you can help me.

CamG777
Scratcher
100+ posts

Script to delete letters from a word enetered by a user.

set [New Word v] to []
set [Counter v] to [1]
ask [word] and wait
repeat (length of (answer))
if <not <[List v] contains (letter (Counter) of (answer)) ?>> then
set [New Word v] to (join (New Word) (letter (Counter) of (answer)))
end
change [counter v] by (1)
end

Last edited by CamG777 (Jan. 18, 2022 01:38:32)

helloworldbyeworld
Scratcher
1000+ posts

Script to delete letters from a word enetered by a user.

CamG777 wrote:

set [New Word v] to []
set [Counter v] to [1]
ask [word] and wait
repeat (length of (answer))
if <not <[List v] contains (letter (Counter) of (answer)) ?>> then
set [New Word v] to (join (New Word) (letter (Counter) of (answer)))
end

end
That won’t work because you need to change the counter at the end of the loop.
CamG777
Scratcher
100+ posts

Script to delete letters from a word enetered by a user.

helloworldbyeworld wrote:

CamG777 wrote:

set [New Word v] to []
set [Counter v] to [1]
ask [word] and wait
repeat (length of (answer))
if <not <[List v] contains (letter (Counter) of (answer)) ?>> then
set [New Word v] to (join (New Word) (letter (Counter) of (answer)))
end

end
That won’t work because you need to change the counter at the end of the loop.

whoops! Will edit to change that. Thanks for pointing it out
monia5305
New Scratcher
5 posts

Script to delete letters from a word enetered by a user.

CamG777 wrote:

helloworldbyeworld wrote:

CamG777 wrote:

set [New Word v] to []
set [Counter v] to [1]
ask [word] and wait
repeat (length of (answer))
if <not <[List v] contains (letter (Counter) of (answer)) ?>> then
set [New Word v] to (join (New Word) (letter (Counter) of (answer)))
end

end
That won’t work because you need to change the counter at the end of the loop.

whoops! Will edit to change that. Thanks for pointing it out


Thanks for your help! I just tried it but is still isn't working for me. I'm not sure why. I'm trying to paste a screenshot of what I'm doing but it doesn;t work
CamG777
Scratcher
100+ posts

Script to delete letters from a word enetered by a user.

Yeah new scratchers can't post screenshoots.

I made a mistake in the code that helloworld pointed out. Did you get the change counter by 1 block?
monia5305
New Scratcher
5 posts

Script to delete letters from a word enetered by a user.

CamG777 wrote:

Yeah new scratchers can't post screenshoots.

I made a mistake in the code that helloworld pointed out. Did you get the change counter by 1 block?

Yes, I've included it in. It is now deleting the letters I need deleted (yay) but is duplicating the first letter of the original word.

So what I'm trying to do:
I've created a list of letters from n-z.
I want these letters to be removed from the word the user enters, for example, if they enter bus, only b should remain. At the moment the B is being repeted 3 times. If I enter london, I end up with LLLLLL because London has 6 letters. Not sure how this is happening. I would like to end up with just Ld as the rest of the letters should be removed.

I hope it makes sense!
CamG777
Scratcher
100+ posts

Script to delete letters from a word enetered by a user.

Well you're doing something wrong because it works for me

https://turbowarp.org/629794105
monia5305
New Scratcher
5 posts

Script to delete letters from a word enetered by a user.

CamG777 wrote:

Well you're doing something wrong because it works for me

https://turbowarp.org/629794105

I'm really not sure what I'm doing wrong
deck26
Scratcher
1000+ posts

Script to delete letters from a word enetered by a user.

monia5305 wrote:

CamG777 wrote:

Well you're doing something wrong because it works for me

https://turbowarp.org/629794105

I'm really not sure what I'm doing wrong
But given this is an assignment (same question has been asked repeatedly in the forum) you shouldn't expect to get your answer presented to you.

If you have a list or variable containing the letters you want to omit all you're doing is buiilding a copy of the text by adding (or not adding) each letter in turn. That's just a basic loop using a coounter variable to move to the next letter and a check against the list or variable that contains the characters.
monia5305
New Scratcher
5 posts

Script to delete letters from a word enetered by a user.

deck26 wrote:

monia5305 wrote:

CamG777 wrote:

Well you're doing something wrong because it works for me

https://turbowarp.org/629794105

I'm really not sure what I'm doing wrong
But given this is an assignment (same question has been asked repeatedly in the forum) you shouldn't expect to get your answer presented to you.

If you have a list or variable containing the letters you want to omit all you're doing is buiilding a copy of the text by adding (or not adding) each letter in turn. That's just a basic loop using a coounter variable to move to the next letter and a check against the list or variable that contains the characters.

Of course, I'm not expecting an answer to be given to me on a plate. I'm just struggling to wrap my head around it. I understand the task, and I know what needs to be done, but for some reason it isn't translating onto the program for me. I'm having a hard time understanding where I'm going wring. That's all
deck26
Scratcher
1000+ posts

Script to delete letters from a word enetered by a user.

monia5305 wrote:

deck26 wrote:

monia5305 wrote:

CamG777 wrote:

Well you're doing something wrong because it works for me

https://turbowarp.org/629794105

I'm really not sure what I'm doing wrong
But given this is an assignment (same question has been asked repeatedly in the forum) you shouldn't expect to get your answer presented to you.

If you have a list or variable containing the letters you want to omit all you're doing is buiilding a copy of the text by adding (or not adding) each letter in turn. That's just a basic loop using a coounter variable to move to the next letter and a check against the list or variable that contains the characters.

Of course, I'm not expecting an answer to be given to me on a plate. I'm just struggling to wrap my head around it. I understand the task, and I know what needs to be done, but for some reason it isn't translating onto the program for me. I'm having a hard time understanding where I'm going wring. That's all
So share what you have and ask for a hint.

Powered by DjangoBB