Discuss Scratch
- Discussion Forums
- » Questions about Scratch
- » How do you create a text box that can be typed into in a game?
- ShipBuilderPerson
-
Scratcher
10 posts
How do you create a text box that can be typed into in a game?
How do you create a text box that can be typed into in a game, but is not using
ask [] and wait?
- Prinseskat
-
Scratcher
1000+ posts
How do you create a text box that can be typed into in a game?
To allow the player to type, you'll need to check for each key on the keyboard that is pressed. If a key is pressed, that letter should be added to a variable to store the user's answer. It might look something like this:
Then, once you've gotten the input, you'll need to display it. This can be used with a text engine. You could look for one on Scratch, or make your own - a text engine needs to loop through each letter in the string, switch costume to the current letter, stamp/clone itself, move a little bit to the right, and repeat.
repeat until <key [space v] pressed>//or another "enter" keyIf you're willing to hack blocks (this topic may help you), you can put a variable into the key pressed slot. Then instead of having 26 if-statements, you can loop through the alphabet:
wait until <key [any v] pressed>
find key pressed
set [input v] to (join (input) (key))
wait until <not <key [any v] pressed>>
end
define find key pressed
if <key [a v] pressed>
set [key v] to [a]
end
if <key [b v] pressed>
set [key v] to [b]
end
etc::grey //repeat for each letter of the alphabet
set [i v] to [1]
set [chars v] to [abcdefghijklmnopqrstuvwxyz]
set [key v] to []//variable that'll "return" the key pressed - blank if no key pressed
repeat (length of (chars))
set [current char v] to (letter (i) of (chars))
if <key (current char) pressed> //will need to "hack" (edit JSON code) to get variable in key pressed boolean
set [key v] to (current char)
stop [this script v]
end
change [i v] by [1]
end
Then, once you've gotten the input, you'll need to display it. This can be used with a text engine. You could look for one on Scratch, or make your own - a text engine needs to loop through each letter in the string, switch costume to the current letter, stamp/clone itself, move a little bit to the right, and repeat.
- FoxboyGaming777
-
Scratcher
35 posts
How do you create a text box that can be typed into in a game?
NVM lol I figured it out
Last edited by FoxboyGaming777 (Oct. 18, 2020 11:11:22)
- FoxboyGaming777
-
Scratcher
35 posts
How do you create a text box that can be typed into in a game?
question is, how to backspace???
- MrFluffyPenguins
-
Scratcher
1000+ posts
How do you create a text box that can be typed into in a game?
question is, how to backspace???its impossible to use backspace
- cs390675
-
Scratcher
5 posts
How do you create a text box that can be typed into in a game?
question is, how to backspace???Use the back arrow instead.
- SpazInfinity
-
Scratcher
1 post
How do you create a text box that can be typed into in a game?
How do you create a text box that can be typed into in a game, but is not usingYou asked how to make a text box without using the ask block, if you want Scratch's built in text box with out the question popping up then just leave it blank, or you can do what Prinseskat suggested to make a custom text box.ask [] and wait?
- Discussion Forums
- » Questions about Scratch
-
» How do you create a text box that can be typed into in a game?





