{This may be the wrong forum - if so appologies. I'm new to Scratch, but I'm a programmer, and I don't mind - indeed would welcome - technical detail in answer to my question.}
Recently I downloaded v 1.4, and started to experiment w/ it on Windows 7. Hopefully the representation of a script below makes sense:
When green flag clicked
set all_sprites_count to 0
set this_sprite_count to 0
show variable all_sprites_count
show variable this_sprite_count
repeat until all_sprites_count = 42
change all_sprites_count by 1
change this_sprite_count by 1
show variable all_sprites_count
show variable this_sprite_count
repeat until all_sprites_count = 0
change all_sprites_count by -1
change this_sprite_count by -1
show variable all_sprites_count
show variable this_sprite_count
(The two counts are "global" and sprite-specific variables, respectively.)
The obseved behaviour, was not as I expected. The counts increased without decreasing at all.
What should I know to understand this?
TIA
Alec
Offline
I'm not sure how this script would not work, there might be something else effecting it.
Anyway, you don't have to tell the script to show the variables so much. However, that probably isn't why this script is working.
I tried recreating a more efficient script, here's what it looks like:
Use that and it should work.
Offline
Thanks for this. I've run your version - but this exibits the same problem. I'll try an un-install and re-install of Scratch. (Thinks - could there be a silent failure of disk write(s), e.g. due to insufficent permissions in running the script?)
Offline
I just tested the script, and it didn't work for me either. I even added "wait (0.001) secs" between each block to make it go slower, but it still didn't work. This is really weird.
Offline
Hi Alec_2 and hmnwilson,
I could not reproduce the effect you are describing. Both counts first increased then decreased again. Could you perhaps post a project that contains the actual script that's not working for you, so we might examine it? Thanks!
Offline
There's a couple things to try:
1) Test it in a different version of scratch. It could be a version-specific bug.
2) Export the sprite, and test it alone. Other scripts could be messing with it.
3) Upload it and try it on the java player. It could be a problem with scratch itself.
4) Put it on single stepping. This lets you see exactly what it is doing at each block.
5) Run each section of the script separately.
These should at least give you an idea why it is happening. Post what happens in each, please, so I can try to help you further.
Offline
Thanks for all the suggestions guys. So far I've only had time to run single-stepping. Somewhat unsurprisingly this shows the expected flow of control down to the end of the first loop - then it goes back though the loop indefinitly, not stopping at the limit value.
Another thought - still clutching at straws - could the 64-bit environment be setting the counts in, e.g. a 32 bit variable, but the loop test failing as the varible is being looked as if it were 64 bits, such that, for some of us, we never see the match condition being met? I see that I can dump the call stack, but are there any other tools that might be relevant here?
Offline
Specifically re Bill's suggestions:
1) I'm reluctant to try different versions of Scratch on this script at the moment, due to lack of time and suspicion that it is an os/program configuration issue
2) There are no other sprites in the project
3) Don't know how to do this yet - tho' I can guess. See also 1).
4) Done, and the results reported in a separate post.
5) Running the initialisation and increment loop behaves as before. Then running the decrement loop decrements the counts, running straight through 0 and into negative numbers.
Offline
This might be my own systems problem but when i tested it with BASIC scratch it worked when i tested the same with (somewhat Modified (shames on self)) version of scratch it bugged .hwnwilson and Alec_2 have u also modified the source code of scratch , some other bugs due to bad source code modification
1. Mouse Position been shown in Presentation Mode (that * me off to reinstall scratch)
2.Cant enter in Preview Mode.
Offline
Bill, did you mean that I post via "Share this project" online? Or something else? I could add scratch blocks below, but hopefully this exchange, in my original post, and particulaly floatingmagictree's reply, give the details.
Offline
Alec_2 wrote:
Thanks for this. I've run your version - but this exibits the same problem. I'll try an un-install and re-install of Scratch. (Thinks - could there be a silent failure of disk write(s), e.g. due to insufficent permissions in running the script?)
You should be VERY careful about performing a test looking for an exact match of a value (variable = 42) particularly in a language that doesn't support the integer data type (such as Scratch). You may be seeing a case of round-off error here, where the value obtained by incrementing the variables is very close to 42 (may even print out as 42) but is slightly different due to the internal representation of the variable.
A much safer approach would be to have a test like
variable > 41
or
ABS(variable - 42) < 0.001
or
Round(variable) = 42
Maybe the last one is the best for your purposes.
Offline
Thanks Paddle2See. Yes I wondered about the variables' numeric type - but in my so-far limited exposure to Scratch scripts, I'd seen examples appearing to use a variable as an integer, and assumed and hoped that this was supported.
Neither of the use of ABS or Round works for me in this example, though. :-(
BTW, going off-topic a bit, is there a link somewhere to a more detailed an formal reference guide to the language than: http://info.scratch.mit.edu/Support/Reference_Guide_1.4 ?
Offline
Alec_2 wrote:
Bill, did you mean that I post via "Share this project" online? Or something else? I could add scratch blocks below, but hopefully this exchange, in my original post, and particulaly floatingmagictree's reply, give the details.
Yes, that's what I meant, as this is a totally different player environment.
I got the script working, as did a few other people, so if you upload it and post a link then we can all see for ourselves exactly what subtle nuisance is causing it.
Offline
OK, Bill thanks. I might get round to that - but as others have got it working, as I expected, I would now expect it to run on most candidate environments. So what do we expect to learn from its running on yet another? (I'm pretty sure that its not a typo in my code - I've re-entered it, and quite a few variants by now.)
So, can I ask those folks who are reading this thread, has anyone else got the expected behaviour when running the distributed executable for 1.4 on a Windows 7 64-bit OS?
And hmnwilson, and any others who have hit this or similar problems - can you confirm what version of Scratch, and OS are you running, and what exactly were the problems?
Offline
I'm using winXP SP3, scratch 1.3.1 using the 1.3.0 EXE and a system with 2 Gigs of RAM and a dual core D820 model.
But I don't think that any of those matter.
Offline
Solved. <blush> Thanks to Amos of the Scratch Team </blush>
I was using the string 'all_sprites_count', rather than the value of that variable, in evaluating the loop termination condition(s). I.e. using the text literal rather than the block itself. ;-(
Offline