Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » scratch how to detect an English letter from the block: ask and wait?
- tomliuwhite
-
99 posts
scratch how to detect an English letter from the block: ask and wait?
The function that I want: detect if there is any English letter input from the block: ask and wait?
Here is the method that I came up with:
The problem is that I need to put 26 ‘if…then…’, it is too complicated, is there any easy way to detect the English letter?
Thanks.
Here is the method that I came up with:
when green flag clicked
ask [Please type] and wait
if <(answer) contains a> then
say [yes]
end
The problem is that I need to put 26 ‘if…then…’, it is too complicated, is there any easy way to detect the English letter?
Thanks.
- awesome-llama
-
1000+ posts
scratch how to detect an English letter from the block: ask and wait?
You can use the same contains block multiple times by putting it in a loop and iterating over a list of letters.
Create a new list and add every letter you want to detect in it as items.
Then, you can make a script like this:
Create a new list and add every letter you want to detect in it as items.
delete all of [list v]::list
add [a] to [list v]
add [b] to [list v]
add [c] to [list v]
add [d] to [list v]
...
Then, you can make a script like this:
ask [Please type] and wait
set [i v] to [1] // variable used for counting
repeat (length of [list v] :: list) // make the loop repeat for every item
if <(answer) contains (item (i) of [list v] :: list) ?> then // check if the current list item (letter) is in the answer
say [yes]
stop [this script v] // this block is optional - if you want to stop checking once a single lettter is found, keep this block
end
change [i v] by (1) // increment counter to go to the next item
end
- tomliuwhite
-
99 posts
scratch how to detect an English letter from the block: ask and wait?
@awesome-llama, good idea, thanks.
- deck26
-
1000+ posts
scratch how to detect an English letter from the block: ask and wait?
Or, rather than a list, you can use a text variable containing ‘abcdefg….’ and loop through that. Just a case of using ‘letter i of text’ rather than ‘item i of list’.
- tomliuwhite
-
99 posts
scratch how to detect an English letter from the block: ask and wait?
@deck26, right, that is another option. Thanks.
- Discussion Forums
- » Help with Scripts
-
» scratch how to detect an English letter from the block: ask and wait?