Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » How to Test without Changing Code?
- jotasprout
-
New Scratcher
14 posts
How to Test without Changing Code?
Is there no way to test your project without changing the code? Is there no way to reset the project to its initial state?
I have several sprites that shouldn't show until a certain point in the game, but if I test it and get to that point, I then have to go into each and every sprite, click the “i”, and deselect “show.” That can't possibly be how Scratch really works!
Is there no basic documentation anywhere?
I've learned Javascript and all its children, PHP, Python … and Scratch is the only thing I've ever had to use that makes me go out of my mind and want to jump off a bridge.
I have several sprites that shouldn't show until a certain point in the game, but if I test it and get to that point, I then have to go into each and every sprite, click the “i”, and deselect “show.” That can't possibly be how Scratch really works!
Is there no basic documentation anywhere?
I've learned Javascript and all its children, PHP, Python … and Scratch is the only thing I've ever had to use that makes me go out of my mind and want to jump off a bridge.
Last edited by jotasprout (Aug. 27, 2016 22:47:43)
- jotasprout
-
New Scratcher
14 posts
How to Test without Changing Code?
Variables, too! How … this is insane. I've never been so frustrated or felt like such an idiot.
- gtoal
-
Scratcher
1000+ posts
How to Test without Changing Code?
Scratch's debugging is abysmal. After a time you get in the habit of building explicit conditional debugging in from the start.
- jotasprout
-
New Scratcher
14 posts
How to Test without Changing Code?
How do I get things to start over from the beginning? Every time I try to test even a single thing I have to go back and reset everything manually (at least those things I can … I still haven't figured out how to get my variables back to their original state). I've been working for two days and can't get anything done because I spend all of my time moving things back, resetting visibility … this is the FIRST assignment in Harvard's CS50 course and I can't move on to any real programming or the rest of the course until I'm done with this nonsense.
- gtoal
-
Scratcher
1000+ posts
How to Test without Changing Code?
How do I get things to start over from the beginning? Every time I try to test even a single thing I have to go back and reset everything manually (at least those things I can … I still haven't figured out how to get my variables back to their original state). I've been working for two days and can't get anything done because I spend all of my time moving things back, resetting visibility … this is the FIRST assignment in Harvard's CS50 course and I can't move on to any real programming or the rest of the course until I'm done with this nonsense.If pressing the green flag doesn't reset your variables, then you are not initialising them in a green flag block. That's the simplest way.
Failing that, as long as your code is saved, reloading the program will load the saved state rather than running with whatever is already in the variables (which are static).
Of course if you've saved after assigning to your variables, you're stuck. You'ld really need to explicitly initialise everything in a green flag block.
- gtoal
-
Scratcher
1000+ posts
How to Test without Changing Code?
See most recent post.
Last edited by gtoal (Aug. 28, 2016 00:07:19)
- gtoal
-
Scratcher
1000+ posts
How to Test without Changing Code?
Experienced programmers are going to be frustrated with Scratch at first, until you learn to adapt to its limitations and not fight them. I do encourage you to stick with it because eventually you'll appreciate the things that it makes easy for you which are hard in other languages, rather than getting annoyed at the things it makes hard for you which are easy in other languages.
Share your projects if you want help - not with the coding, but having been through the ‘real language to Scratch’ conversion learning curve myself, I may be able to steer you away from some generic pitfalls.
Graham
Share your projects if you want help - not with the coding, but having been through the ‘real language to Scratch’ conversion learning curve myself, I may be able to steer you away from some generic pitfalls.
Graham
- jotasprout
-
New Scratcher
14 posts
How to Test without Changing Code?
The variables are the least of my concern because I know I can have the green flag set them to a default value.
There has to be a way to play/test these projects separately from the editing environment. There's no other programming language or tool I know of where playing/running a project changes the code like this. This is insanity.
There has to be a way to play/test these projects separately from the editing environment. There's no other programming language or tool I know of where playing/running a project changes the code like this. This is insanity.
- gtoal
-
Scratcher
1000+ posts
How to Test without Changing Code?
In the green flag block you can move your sprites to their initial positions with code (much safer than dragging them where you want initially with the editor, which is what I think you may have been doing), and explicitly use the ‘show’ or ‘hide’ blocks so that you don't need to reset them manually in the editor. Generally any sort of manual drag&drop initialisation in Scratch is a bad idea.
If you're not sure of the x/y coords to use when initially placing sprites with “goto x y”, the cursor values are displayed in the stage window - so position the cursor over the center of the sprite for a quick approximation. Or select the ‘motion’ blocks and place a check mark left of the ‘x position’ and ‘y position’ reporters for the exact coordinates. Then add a goto x: () y: () in the green flag area with the numbers you found.
Also in the green flag block, use ‘hide’ from the ‘looks’ area to suppress the sprite display until you want it.
G
If you're not sure of the x/y coords to use when initially placing sprites with “goto x y”, the cursor values are displayed in the stage window - so position the cursor over the center of the sprite for a quick approximation. Or select the ‘motion’ blocks and place a check mark left of the ‘x position’ and ‘y position’ reporters for the exact coordinates. Then add a goto x: () y: () in the green flag area with the numbers you found.
Also in the green flag block, use ‘hide’ from the ‘looks’ area to suppress the sprite display until you want it.
G
Last edited by gtoal (Aug. 28, 2016 00:06:50)
- footsocktoe
-
Scratcher
1000+ posts
How to Test without Changing Code?
Is there no way to test your project without changing the code? Is there no way to reset the project to its initial state?
I have several sprites that shouldn't show until a certain point in the game, but if I test it and get to that point, I then have to go into each and every sprite, click the “i”, and deselect “show.” That can't possibly be how Scratch really works!
Is there no basic documentation anywhere?
I've learned Javascript and all its children, PHP, Python … and Scratch is the only thing I've ever had to use that makes me go out of my mind and want to jump off a bridge.
Think of it in terms of a session. If you want to reset everything, then close the session and open a new one. In other words, close the project and open it again.
However, it's much simpler just to realize that if you add a block that changes something, it will stay changed unless you change it back.
So for example, if at a certain point in the project you hide a sprite, then you know you should also add a show block under it's green flag.
If at a certain point in a project you ghost a sprite to 100%, then you know you also need to add a “set ghosting to 0%” block under it's green flag.
If at a certain point in a project you resize a sprite to 50%, then you know you have to add a “set size to 100%” block under its green flag.
This is actually very convenient, because you don't have to initialize EVERYTHING, you only have to initialize the things the project changes.
If you do that, then clicking the green flag gets you back to start with no problems.
Last edited by footsocktoe (Aug. 28, 2016 01:08:47)
- TheLogFather
-
Scratcher
1000+ posts
How to Test without Changing Code?
No, Scratch doesn't have any such problem that you're describing. If you know you can initialise variables on GreenFlag, why can't you initialise the positions/costumes/etc. of the sprites…?
After re-reading your original post, I can't say I really understand what the problem is – AFAICT, you just seem to be simply missing the scripting you should have to set up these things at the start…? (Just as gtoal said in his later post.)
Here are a few further tips about using Scratch, particularly as your projects become more complex…
One thing that's important to remember is to initialise things (e.g. variables, sprite positions, visibility, etc.) that are needed for a particular new part of a project (e.g. when it first starts, or at a new level) *before* you actually begin whatever loop(s) it needs to run – particularly if the loops have some terminating condition.
It's a very common mistake to have a loop which starts running ‘at the same time’ as other scripts elsewhere that are initialising some variable that's used in the loop. Since you don't really know what order Scratch will start up those scripts (unless you're aware of exactly how it decides such things), then you don't know if it'll start the first pass through the loops *before* you've initialised the vars/sprites/etc. that the loops will use.
The easiest way to ensure things get done in the right order is to use a broadcast chain. I.e. in some ‘main’ sprite (or stage) you do something like "broadcast [initialise start] and wait“ followed by ”broadcast [start game]“ or something. Then your sprites can set up themselves (e.g. costumes, positions, etc.) and their vars in the appropriate way in response to the first broadcast before the ”start game" broadcast is sent which actually starts the main loop(s).
Also, if you script things in an event-driven way using broadcasts then you shouldn't have problems with starting a project from any specific well-defined point (e.g. a new level, etc.) If you want to test something from a particular point then all you should have to do is send the appropriate broadcast. All the sprites/clones should then (if you've done it right) respond in the way appropriate to that point in your project (e.g. a specific level of a game, etc.)
Furthermore, I'd recommend that, at any point during running of your project, you only have a single main loop which controls everything else by sending a broadcast at each pass through it. That makes it *really* easy to control how & when things happen in all the other sprites/clones.
Hope those help!
After re-reading your original post, I can't say I really understand what the problem is – AFAICT, you just seem to be simply missing the scripting you should have to set up these things at the start…? (Just as gtoal said in his later post.)
Here are a few further tips about using Scratch, particularly as your projects become more complex…
One thing that's important to remember is to initialise things (e.g. variables, sprite positions, visibility, etc.) that are needed for a particular new part of a project (e.g. when it first starts, or at a new level) *before* you actually begin whatever loop(s) it needs to run – particularly if the loops have some terminating condition.
It's a very common mistake to have a loop which starts running ‘at the same time’ as other scripts elsewhere that are initialising some variable that's used in the loop. Since you don't really know what order Scratch will start up those scripts (unless you're aware of exactly how it decides such things), then you don't know if it'll start the first pass through the loops *before* you've initialised the vars/sprites/etc. that the loops will use.
The easiest way to ensure things get done in the right order is to use a broadcast chain. I.e. in some ‘main’ sprite (or stage) you do something like "broadcast [initialise start] and wait“ followed by ”broadcast [start game]“ or something. Then your sprites can set up themselves (e.g. costumes, positions, etc.) and their vars in the appropriate way in response to the first broadcast before the ”start game" broadcast is sent which actually starts the main loop(s).
Also, if you script things in an event-driven way using broadcasts then you shouldn't have problems with starting a project from any specific well-defined point (e.g. a new level, etc.) If you want to test something from a particular point then all you should have to do is send the appropriate broadcast. All the sprites/clones should then (if you've done it right) respond in the way appropriate to that point in your project (e.g. a specific level of a game, etc.)
Furthermore, I'd recommend that, at any point during running of your project, you only have a single main loop which controls everything else by sending a broadcast at each pass through it. That makes it *really* easy to control how & when things happen in all the other sprites/clones.
Hope those help!
Last edited by TheLogFather (Aug. 28, 2016 09:05:56)
- deck26
-
Scratcher
1000+ posts
How to Test without Changing Code?
The variables are the least of my concern because I know I can have the green flag set them to a default value.Essentially there are no default settings which always apply at the start of a project.
There has to be a way to play/test these projects separately from the editing environment. There's no other programming language or tool I know of where playing/running a project changes the code like this. This is insanity.
Nothing changes the code except you in the editor. The thing that changes is the state of objects such as whether they're hidden or ghosted or have particular costumes but all of these should be initialised at the start of the project run if a previous run may have left them in a different state. So it's really just a case of treating these things in the same way as you'd treat variables and making sure things are set properly at the start.
Anything that never gets changed doesn't need resetting but anything that might change should really be reset.
- jotasprout
-
New Scratcher
14 posts
How to Test without Changing Code?
Thank you so much to all of you for your patience and detailed replies – you're definitely all a friendly and helpful community.
- Gauteng
-
New Scratcher
1 post
How to Test without Changing Code?
Good day
How do I test or preview if my project is working?
Regards
Saul
How do I test or preview if my project is working?
Regards
Saul
- deck26
-
Scratcher
1000+ posts
How to Test without Changing Code?
Good dayPlease create your own new topic rather than necroposting.
How do I test or preview if my project is working?
Regards
Saul
You test your project by running it and seeing if it does what you expect. The more complex the project the more testing of different scenarios is required unless you code in such a way that separate components can be tested separately.
- 1990skid56
-
Scratcher
72 posts
How to Test without Changing Code?
Is there no way to test your project without changing the code? Is there no way to reset the project to its initial state?
I have several sprites that shouldn't show until a certain point in the game, but if I test it and get to that point, I then have to go into each and every sprite, click the “i”, and deselect “show.” That can't possibly be how Scratch really works!
Is there no basic documentation anywhere?
I've learned Javascript and all its children, PHP, Python … and Scratch is the only thing I've ever had to use that makes me go out of my mind and want to jump off a bridge.
You can just copy the link of your project and test it on incognito.
- Harakou
-
Scratcher
1000+ posts
How to Test without Changing Code?
Hi! Thank you for offering your help, but this thread is pretty old - I don't think it's relevant anymore. When you respond to a topic, please make sure it's recent and the original poster still needs an answer. Thanks!Is there no way to test your project without changing the code? Is there no way to reset the project to its initial state?
I have several sprites that shouldn't show until a certain point in the game, but if I test it and get to that point, I then have to go into each and every sprite, click the “i”, and deselect “show.” That can't possibly be how Scratch really works!
Is there no basic documentation anywhere?
I've learned Javascript and all its children, PHP, Python … and Scratch is the only thing I've ever had to use that makes me go out of my mind and want to jump off a bridge.
You can just copy the link of your project and test it on incognito.
- Discussion Forums
- » Help with Scripts
-
» How to Test without Changing Code?