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

#1 2012-07-09 13:35:46

frank1281
Scratcher
Registered: 2008-10-12
Posts: 100+

Walking - Running Glitch?

I am making a 2D scroller game called evolution. One of the functions is walking & running. Forever, if the up arrow key is pressed, the player moves up. If the up arrow key AND the 'r' key are pressed, the player runs up. This works with every arrow key. I made it so that when you walk, it says:

when gf clicked
forever
if <pause = 0>
if <<key [up arrow] pressed> and <not <key [r] pressed>>>
point in direction (0)
switch to costume (walk up)
wait (speed/10)
else
if <<key [up arrow] pressed> and <key [r] pressed>>
point in direction (0)
switch to costume (walk up)
wait (speed/25)
end
 
and

when gf clicked
forever
if <pause = 0>
if <<key [up arrow] pressed> and <(5) > (walk up)>>
if <<not<key [r]>pressed>>
change [walk up] by (1)
wait (speed/10)
else
change (walk up) by (1)
wait (speed/25)
end
 
The problem is that when I press the up arrow key AND the 'r' key, it moves at the same speed than when I DON'T press the 'r' key, even though I put <(speed) / (10)> when the 'r' key isn't pressed, and <(speed) / (25)> when the r'r key IS pressed. Oh btw, the "speed" variable = 1, but that is something that will change depending on how far ahead you are in the game.
In the beginning it worked properly, but now I dont know what happened. Perhaps I accidentaly touched or modified something and didn't realize it, or the game is just too heavy (which it really is) for my computer, which is really slow (or it's a problem with Scratch, which isn't made to withstand such heavy & large games).


http://i55.tinypic.com/309h9hi.jpg Your Job is to Take Everyone Down, Or Die Trying.
Hunt or Be Hunted

Offline

 

#2 2012-07-09 14:20:31

henley
Scratcher
Registered: 2008-06-21
Posts: 1000+

Re: Walking - Running Glitch?

frank1281 wrote:

when gf clicked
forever
if <(pause) = [0]>
if <<key [up arrow v] pressed?> and <not <key [r v] pressed?>>>
point in direction (0 v)
switch to costume [walk up v]
wait ((speed) / [25]) secs
else
if <<key [up arrow v] pressed?> and <key [r v] pressed?>>
point in direction (0 v)
switch to costume [walk up v]
wait ((speed) / [25]) secs
end
 
and

when gf clicked
forever
if <(pause) = [0]>
if <<key [up arrow v] pressed?> and <(5) > (walk up)>>
if <not<key [r v]pressed?>>
change [walk up v] by (1)
wait ((speed) / [10]) secs
else
change [walk up v] by (1)
wait ((speed) / [25]) secs
end
 

I fixed up your scripts for you so that people will more easily understand them.

Last edited by henley (2012-07-09 14:23:18)


"I've worked so hard for you and you give me nothing in return. Do you need help... Or do I?"

Offline

 

#3 2012-07-09 14:33:49

henley
Scratcher
Registered: 2008-06-21
Posts: 1000+

Re: Walking - Running Glitch?

I don't see why you don't just do this:

when gf clicked
forever
if <key [up arrow v] pressed?>
    switch to costume [walk up v]
    point in direction (0 v)
    if <key [r v] pressed?>
        move [10] steps
    else
        move [5] steps
    end
end
end
It should work just the same. Unless you want fancy smooth movement. If you want that, I'll post it later


"I've worked so hard for you and you give me nothing in return. Do you need help... Or do I?"

Offline

 

#4 2012-07-09 15:06:19

frank1281
Scratcher
Registered: 2008-10-12
Posts: 100+

Re: Walking - Running Glitch?

I don't, because it's a scroller game, which means that the player doesn't move, but the floor moves around him. It's an illusion, more or less. What I'm doing is just changing his costume so that it looks as if he were moving, and the variables are to change how fast his costumes change, therefore it looks as if he were running faster.


http://i55.tinypic.com/309h9hi.jpg Your Job is to Take Everyone Down, Or Die Trying.
Hunt or Be Hunted

Offline

 

#5 2012-07-09 15:26:13

henley
Scratcher
Registered: 2008-06-21
Posts: 1000+

Re: Walking - Running Glitch?

I see.

Then why not just do this?

when gf clicked
forever
if <key [up arrow v] pressed?>
    switch to costume [walk up v]
    point in direction (0 v)
    if <key [r v] pressed?>
        set [walk up v] to (10)
    else
        set [walk up v] to (5)
    end
end
end


"I've worked so hard for you and you give me nothing in return. Do you need help... Or do I?"

Offline

 

Board footer