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

#1 2007-05-27 07:10:37

nemouno
Scratcher
Registered: 2007-05-26
Posts: 8

about variable

I created a variable named : key
When i press a key it'll change by 1
but why i do so , it changes by .... who knows xD : at least 3 or 4

PLease tell me how to fix it  sad (

Offline

 

#2 2007-05-27 07:39:39

mres
Scratch Team
Registered: 2007-03-08
Posts: 48

Re: about variable

Can you post the actual code that you are using, so that we can help debug it?

Is the code checking for the key-press inside some type of loop? If so, perhaps it is incrementing the variable several times while you are holding down the key?

Offline

 

#3 2007-05-27 14:32:15

kevin_karplus
Scratcher
Registered: 2007-04-27
Posts: 1000+

Re: about variable

If you are holding down a key you may be getting autorepeat from your keyboard.
Like thisssssssssssssssssssssssssss

Offline

 

#4 2007-05-27 20:25:50

nemouno
Scratcher
Registered: 2007-05-26
Posts: 8

Re: about variable

@kevin : i just press once  big_smile

@ this is how i got probs

When i receive "start" ( when i press my mouse it'll broadcast "start" - no probs here )
forever if : arrow pressed
changed "key" by 1 ( key is variable )

thanks for helping  big_smile

Offline

 

#5 2007-05-27 20:33:47

jay
Scratch Team
Registered: 2007-03-11
Posts: 59

Re: about variable

Ahhh nemouno, I see what is happening. When you use
forever if: arrow pressed
it is "constantly" checking if the arrow is pressed, and if so it changes "key" by 1. But it checks so fast that it changes "key" many times in the short period of time that you push down the arrow. I would recommend putting a wait block into the "forever if" loop. Or, if I wanted to take a different approach, I would use the control block "when ____ key pressed"

Offline

 

#6 2007-05-27 20:40:18

nemouno
Scratcher
Registered: 2007-05-26
Posts: 8

Re: about variable

big_smile 
thx  big_smile 

but if with that code
aniwei to fix ??

Offline

 

#7 2007-05-27 20:47:41

nemouno
Scratcher
Registered: 2007-05-26
Posts: 8

Re: about variable

Anyone make PacMan yet  sad (

Offline

 

#8 2007-05-27 20:49:33

jay
Scratch Team
Registered: 2007-03-11
Posts: 59

Re: about variable

do you mean with the code you have now is there any way to fix it? i'd try putting a
"wait 1 second"
block into the loop

If that isn't what you're asking can you post again with more description? You can even upload your project that you want help on if you want to.

Offline

 

#9 2007-05-27 21:07:14

nemouno
Scratcher
Registered: 2007-05-26
Posts: 8

Re: about variable

i've changed the code - so i'll finish the project first  sad

im not good at english much  tongue
but i still can say the way i want that code works like this :

With 4 arrows - in about 15s - i press 4 arrows randomly
so with each arrow - 1 symbol appear from left to right

and after pressing 4 arrow - i cant press animore

-- so i make a variable here to count the times arrow pressed

---- i guess no-one will understand wad im talking  smile )
my writing skill iz bad T~T

Offline

 

#10 2007-05-28 03:06:24

kevin_karplus
Scratcher
Registered: 2007-04-27
Posts: 1000+

Re: about variable

Instead of using  "if arrow pressed" try using a script that starts with "when arrow clicked"

Offline

 

#11 2007-05-28 06:49:21

nemouno
Scratcher
Registered: 2007-05-26
Posts: 8

Re: about variable

how to click arrow on keyboard ??/ xD

Offline

 

#12 2007-05-29 10:19:13

tammyadmin
Scratcher
Registered: 2007-05-12
Posts: 2

Re: about variable

Hi nemouno,

What if you had these four scripts:

When <up arrow> key pressed
  change key by <1>

When <down arrow> key pressed
  change key by <1>

When <left arrow> key pressed
  change key by <1>

When <right arrow> key pressed
  change key by <1>

Then you could have another script that checks the value of key and stops the program if it equals 4:

forever if <key = 4>
  stop all

Does that help?
-Tammy

Offline

 

Board footer