Hello,
I am a student at the OU learning Sense/Scratch, I seem to be stuck on a bit of code and could do with a nudge in the right direction.
I am building a very basic word processor, when a key is pressed on the keyboard the letter is printed on the stage:
when [h] key pressed pen down point in direction [0] move (30) steps point in direction [180] move (15) steps point in direction [90] move (20) steps point in direction [0] move (15) steps point in direction [180] move (30) steps set [keyPressed] to [true]I have scripts assembled for other characters and numbers, this works for what I need and when a key is pressed it gets drawn on the stage - cool stuff!
when gf clicked clear set pen size to (3) pen up go to x: [-220] y: [140] point in direction [90] forever if <<keyPressed> = [true]> pen up point in direction [90] go to x: <<x position> + [20]> y: [140] end endThe only problem is when I run the script nothing runs within my If block and it seems to get ignored, despite keyPressed been true when I hit one of the keys.
Offline
I don't see any reason for in not to work.
Offline
Can you upload the project so I can take a closer look?
Offline
Sorry not to sure how to upload my project, I am using sense which is the same as scratch but does not include a share button. You can download my project from http://www.filefactory.com/file/1ifcxchoc4q7/n/myproject_sb
It definitely does not work as intended, when the green flag is clicked the sprite just shoots off the stage!!!!
Offline
Add set [keyPressed v] to [false] at the top of the green flag hat stack, and also at the end of the if clause.
Offline
Fantastic thank you so much, can you tell me why the variable needed to be set to false? I was under the impression it was false until the key was pressed then it was set true?
Offline
You can probably do this without a variable or an if block by always positioning the sprite at the end of a letter so that it is ready to draw the next one. You would probably want to left the pen up before that final positioning though.
Offline
bobinthebag wrote:
Fantastic thank you so much, can you tell me why the variable needed to be set to false? I was under the impression it was false until the key was pressed then it was set true?
Because once being set to true, there was nothing else telling it to go back to being false.
EDIT: Oops, forgot to rainbowify!
Last edited by scimonster (2012-04-22 13:25:39)
Offline
Thanks for your help guys, Paddle2See that's an interesting point however I think the assignment is more aimed towards basic use of setting variables and making use of if blocks. I now understand how to carry out instructions within an if block when a control operator says variable name = true (whoopy)! As scimonster says, once true there was nothing setting it back to false, which is why my sprite was flying off the stage! lol.
Offline
scimonster wrote:
Add set [keyPressed v] to [false] at the top of the green flag hat stack, and also at the end of the if clause.
Hi there, im having a simliar problem as the OP. Could you explain what Add set [keyPressed v] to [false] is please?
Offline
Bigdave89 wrote:
scimonster wrote:
Add set [keyPressed v] to [false] at the top of the green flag hat stack, and also at the end of the if clause.
Hi there, im having a simliar problem as the OP. Could you explain what Add set [keyPressed v] to [false] is please?
You need to add the block
set [keyPressed v] to [false]to start of each stamping script.
Offline
@bobinthebag- Your intuition that a variable should be false until set to be true would seem right, but unlike in most programming languages, Scratch's variables retain their values even when the program is not running. This allows the programmer to store massive amounts of data in variables or lists without telling the program to populate the list upon each execution. Likewise, variables who are assigned a value never stop holding that value unless they are told to do so.
Offline
scimonster wrote:
bobinthebag wrote:
Fantastic thank you so much, can you tell me why the variable needed to be set to false? I was under the impression it was false until the key was pressed then it was set true?
Because once being set to true, there was nothing else telling it to go back to being false.
EDIT: Oops, forgot to rainbowify!
Umm... This is correct...
Last edited by ImagineIt (2012-04-25 16:54:09)
Offline
I don't think that all of the obsolete blocks really help. Maybe there is a sense forum?
Offline