Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » pressing number keys script
- A_Broadhurst
-
Scratcher
100+ posts
pressing number keys script
I have a script (example shown below) that if a number key is pressed i.e 1 then it should allow another number key to be pressed, influencing the output. For example if I pressed 1 then 2 then it produce 12. but instead its taking the first number input twice which creates 11 instead. Although I don't want to rule out 11 altogether.
BTW if they press space, then none of the if statement would be activated and no output is produced.
if <key [1 v] pressed?> then
change [no v] by (1)
wait until <<key [space v] pressed?> or <<key [1-9 v] pressed?> >>
if <key [1 v] pressed?> then
change [no v] by (11)
if <key [2 v] pressed?> then
change [no v] by (12)
end
end
end
BTW if they press space, then none of the if statement would be activated and no output is produced.
- A_Broadhurst
-
Scratcher
100+ posts
pressing number keys script
I have a script (example shown below) that if a number key is pressed i.e 1 then it should allow another number key to be pressed, influencing the output. For example if I pressed 1 then 2 then it produce 12. but instead its taking the first number input twice which creates 11 instead. Although I don't want to rule out 11 altogether.when I mean no output, I mean the first number that is pressed is made the output i.e instead if 11 it would be 1if <key [1 v] pressed?> then
change [no v] by (1)
wait until <<key [space v] pressed?> or <<key [1-9 v] pressed?> >>
if <key [1 v] pressed?> then
change [no v] by (11)
if <key [2 v] pressed?> then
change [no v] by (12)
end
end
end
BTW if they press space, then none of the if statement would be activated and no output is produced.
- Theprodigy
-
Scratcher
100+ posts
pressing number keys script
You can try this:
Hope this helps.
repeat until <key [space v] pressed?>keep doing that until you have up to 9.
If <key [1 v] pressed?> then
Set [number v] to (join (number)(1))
else
If <key [2 v] pressed?> then
...
else
...
end
end
end
Hope this helps.
- A_Broadhurst
-
Scratcher
100+ posts
pressing number keys script
You can try this:repeat until <key [space v] pressed?>keep doing that until you have up to 9.
If <key [1 v] pressed?> then
Set [number v] to (join (number)(1))
else
If <key [2 v] pressed?> then
...
else
...
end
end
end
Hope this helps.
no it is still producing 11 instead of 1
- Math_Addict
-
Scratcher
100+ posts
pressing number keys script
when [0 v] key pressedThere are things like the one above.
- A_Broadhurst
-
Scratcher
100+ posts
pressing number keys script
when [0 v] key pressedThere are things like the one above.
that still won't help as it would just take the first key again creating 11 when I would want to create 1 or 12
- Theprodigy
-
Scratcher
100+ posts
pressing number keys script
just add
and repeat for each subsequent #
wait until <not<key [1 v] pressed?>>add this before the set variable block.
and repeat for each subsequent #
Last edited by Theprodigy (July 22, 2014 13:49:38)
- A_Broadhurst
-
Scratcher
100+ posts
pressing number keys script
just addwait until <not<key [1 v] pressed?>>add this before the set variable block.
and repeat for each subsequent #
still not working, can you have a look for me? http://scratch.mit.edu/projects/24454956/
looking inside sprite 11
- Theprodigy
-
Scratcher
100+ posts
pressing number keys script
Check this out: http://scratch.mit.edu/projects/24944283/
I deleted all the code and sprites aside from the one that pertains to your question. If you like it you can put the script in your backpack, and use it in your project.
Hope this helps, and good luck
I deleted all the code and sprites aside from the one that pertains to your question. If you like it you can put the script in your backpack, and use it in your project.
Hope this helps, and good luck
- Discussion Forums
- » Help with Scripts
-
» pressing number keys script