Pages: 1
Topic closed
One small problem I've encountered in my early days of Scratch programming is getting 'clean' inputs...
If I use the keys for movement with sensor 'key pressed' there's the standard Windows pause before auto-repeat kicks in.... so I get * one movement * short pause * continuous movement *
Meanwhile, when I'm taking mouse button input, I'm getting the reverse problem - when I just want to take the first mouse click (using sensor 'mouse down'), I often get 2 or 3 hits. In my Connectorius project this leaves me with the side effect that some shots use, for example, 5 power units, but other shots use 10 or 15, even though I feel like I've clicked as 'lightly' as possible.
I've not yet worked out a way around these challenges... is there a standard way around them? Or do I just need to accept them and try and mitigate them in the gameplay design?
Any ideas gratefully received
Last edited by SonicPopsDad (2008-07-31 10:56:01)
Offline
A way around the pause before repeat is to do
If <key (whatever key) pressed>
do action
========
and a way around the mouse click is to do
if < <mouse down> and <touching mouse-pointer> >
do action
wait until <not <mouse down> >
Or you could do (for the mouse), use the when (sprite) clicked hat, but there is a delay and you can't put it into wait untils or anything.
Hope this helped!
Last edited by coolstuff (2008-07-31 11:07:04)
Offline
Coolstuff,
I'm not sure I get the key example (which is a bit embarrassing as it looks so simple!), because it looks the same as the movement routine I wrote this morning (for an Asteroids game), which looked like this (iirc)...
Spaceship sprite
forever
if key Left Arrow pressed
rotate ...
if key Right Arrow pressed
rotate ...
(repeat)
However I definitely *do* get the mouse one, that's great and should cure my problem! thankyou!
Offline
SonicPopsDad wrote:
Coolstuff,
I'm not sure I get the key example (which is a bit embarrassing as it looks so simple!), because it looks the same as the movement routine I wrote this morning (for an Asteroids game), which looked like this (iirc)...
Spaceship sprite
forever
if key Left Arrow pressed
rotate ...
if key Right Arrow pressed
rotate ...
(repeat)
However I definitely *do* get the mouse one, that's great and should cure my problem! thankyou!
Hm... the repeat-after-wait thinghymabobber only happens really when I use the when ___ key pressed hat (script header). I don't know what could've happened there.
Offline
This project here shows a common approach to handling the key press lag issue:
http://scratch.mit.edu/projects/Paddle2SeeFixIt/168376
Offline
You know, I should really answer these forum posts when I'm at home, and I can try to replicate my original problems ...
I can't remember what I did that made the key board input work poorly, but Paddle2See, the project you posted works perfectly (though it's what I htought I'd originally done!) ... I copied the code into my Defender game, and it's great
(I''ve now got mouse *and* keyboard input working for it, which will suit old-school gamers like me!)
edit: oh yeah, Coolstuff mentioned it - must've used the 'when key pressed' block rather than the sensor module
Last edited by SonicPopsDad (2008-08-01 09:27:45)
Offline
Or if you are broadcasting something from using the mouse, you can always do broadcast _____ and wait. This means that the loop pauses until all of the actions are completed. Also if you want something to hide when you click it remember to put hide in before broadcasting and changes of variables.
Offline
I think this is the "problem":
[blocks]
<when[ ]key pressed>
[/blocks]
This is an event: it depends on the key repeat in windows. Try holding a kay in wordpad and see what happens...
[blocks]
<key[ ]pressed?>
<mouse down?>
[/blocks]
These variables are actually some kind of boolean variables: true/false. When you put in a loop it might loop or more times trough it because the condition keeps true. Adding a 0.1 wait might solve the problem.
Offline
JSO wrote:
Adding a 0.1 wait might solve the problem.
Another way (which I almost always use) is a [wait until <not <mouse down> >] block. Then, even if the user holds the mouse down for a bit longer (my mouse sometimes thinks I'm pressing for longer than I am), it still has the same effect.
Offline
cheers guys, I've got a new project http://scratch.mit.edu/projects/SonicPopsDad/231508 which makes use of the mouse wait. I've got another project on the go which actually uses the single-key input effect as a positive thing, so it's good we've got access to alternatives!
newareagle: thanks for pointing out 'broadcast and wait' ... I hadn't noticed that, I've used 'waits' and timers to get around any issues I've had - that way will be nicer
Offline
Topic closed
Pages: 1