This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2012-12-05 14:13:40

Linkquest
New Scratcher
Registered: 2012-12-05
Posts: 4

Key 'S'

Ok, so I made a script which swings a sword, but for some unknown reason the script doesn't run while pressing 's' (down) + 'd' (right) or 'a' (left), but if I press down arrow + right arrow or left arrow, it runs. I've changed the controls several times and 's' seems like the the only key + left or right that doesn't work. So if anyone knows why this happens or how to fix it, please help me.



when gf clicked //moving down
forever
if  <key (s) pressed?>
change y by (-4)
end
end
when gf clicked //moving right
forever
if <key (d) pressed?>
change x by (4)
end
end
when gf clicked //swinging the sword
forever
if <<key (space) pressed?> and <(direction) = [90]>>
point in direction (0)
show
repeat until <<(direction) = [140]> or  <(direction) > [140]>>
turn right (20) degrees
end
hide
point in direction (90)
wait (0.1) secs
end
end

Offline

 

#2 2012-12-05 14:29:33

Linkquest
New Scratcher
Registered: 2012-12-05
Posts: 4

Re: Key 'S'

If it helps here is a link to my project: http://scratch.mit.edu/projects/Linkquest/2954556

Offline

 

#3 2012-12-05 15:10:24

dankill51
Scratcher
Registered: 2012-01-22
Posts: 85

Re: Key 'S'

Weird.. It works for me

Offline

 

#4 2012-12-05 15:17:36

SketchSmozzick
Scratcher
Registered: 2012-06-22
Posts: 8

Re: Key 'S'

Looking at your scripts the most likely problem with them is that you have three different forever loops running within that script at the same time each with different parts of the controls in.
The problem with this is that scripts don't run simultaneously so while it's checking what happens when d is pressed it can't go check on what should happen when d is pressed.
To solve the problem you should keep the controls in one loop using if and if elses as necesssary.

e.g.

when gf clicked
forever
if <key [a v] pressed?>
change x by [-4]
else
if <key [d v] pressed?>
change x by [4]
end
end

if <key [w v] pressed?>
change y by [4]
else
if <key [s v] pressed?>
change y by [-4]
end
end


end

Last edited by SketchSmozzick (2012-12-05 15:18:07)

Offline

 

#5 2012-12-05 21:57:32

Linkquest
New Scratcher
Registered: 2012-12-05
Posts: 4

Re: Key 'S'

hmm, just tested on my home computer and worked just fine, might just be the stupid school computers.

Offline

 

#6 2012-12-06 09:04:02

Smozzick
Scratcher
Registered: 2011-10-23
Posts: 100+

Re: Key 'S'

It's likely that it will work for faster computers but that slower computers will have trouble, I think.


http://i50.tinypic.com/ded8m.png

Offline

 

#7 2012-12-06 11:31:32

zammer990
Scratcher
Registered: 2012-01-22
Posts: 500+

Re: Key 'S'

SketchSmozzick wrote:

Looking at your scripts the most likely problem with them is that you have three different forever loops running within that script at the same time each with different parts of the controls in.
The problem with this is that scripts don't run simultaneously so while it's checking what happens when d is pressed it can't go check on what should happen when d is pressed.
To solve the problem you should keep the controls in one loop using if and if elses as necesssary.

e.g.

when gf clicked
forever
if <key [a v] pressed?>
change x by [-4]
else
if <key [d v] pressed?>
change x by [4]
end
end

if <key [w v] pressed?>
change y by [4]
else
if <key [s v] pressed?>
change y by [-4]
end
end


end

I don't like that script, it makes it so that if I were to press d, then start pressing a, i would stop moving right and start moving left


http://i45.tinypic.com/2ynq7nn.jpg Play now!

Offline

 

#8 2012-12-06 16:08:09

Smozzick
Scratcher
Registered: 2011-10-23
Posts: 100+

Re: Key 'S'

True but that isn't really that problematic. If you're pressing left and right at the same time then odd behaviour should be expected.

But it would be better if it just stopped. I was more focused on stopping the described problem at the time but there are ways to correct it like using velocity and moving the set velocity and such.

Could also fix it by just putting each in separate if's but you can get a bit of jitter then and it isn't a very neat way to fix it.

Last edited by Smozzick (2012-12-06 16:08:56)


http://i50.tinypic.com/ded8m.png

Offline

 

Board footer