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
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
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
Offline
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)
Offline