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

#1 2010-02-24 06:08:19

Alec_2
Scratcher
Registered: 2010-02-24
Posts: 10

Use of variables

{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

 

#2 2010-02-24 07:14:42

floatingmagictree
Scratcher
Registered: 2008-10-21
Posts: 1000+

Re: Use of variables

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:
http://img705.imageshack.us/img705/2937/scripthelp.gif
Use that and it should work.

Offline

 

#3 2010-02-24 12:14:42

Alec_2
Scratcher
Registered: 2010-02-24
Posts: 10

Re: Use of variables

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

 

#4 2010-02-24 12:18:57

Greenboi
Scratcher
Registered: 2010-01-30
Posts: 1000+

Re: Use of variables

Hmm... Maybe a mod should help.  wink

Offline

 

#5 2010-02-24 14:50:47

hmnwilson
Scratcher
Registered: 2007-07-04
Posts: 1000+

Re: Use of variables

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.


I'm taking a break from Scratch until 2.0 comes out. Any messages sent between then and now probably won't be read - sorry.
(Oct. 20, 2011)

Offline

 

#6 2010-02-24 19:08:14

Jens
Scratcher
Registered: 2007-06-04
Posts: 1000+

Re: Use of variables

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!


Jens Mönig

Offline

 

#7 2010-02-24 20:31:25

billyedward
Scratcher
Registered: 2008-01-03
Posts: 500+

Re: Use of variables

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.


"I'd love to change the world, but they haven't released the source code yet."
Check out the latest version of Streak --> http://billy.scienceontheweb.net/Streak

Offline

 

#8 2010-02-25 07:23:53

Alec_2
Scratcher
Registered: 2010-02-24
Posts: 10

Re: Use of variables

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

 

#9 2010-02-25 07:37:45

Alec_2
Scratcher
Registered: 2010-02-24
Posts: 10

Re: Use of variables

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

 

#10 2010-02-25 08:36:14

fanofcena
Scratcher
Registered: 2008-07-03
Posts: 1000+

Re: Use of variables

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.


http://i53.tinypic.com/2vxr2c0.png Click whats above u might make a cute planet happy ^_^

Offline

 

#11 2010-02-25 09:23:45

Alec_2
Scratcher
Registered: 2010-02-24
Posts: 10

Re: Use of variables

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

 

#12 2010-02-25 09:33:29

Paddle2See
Scratch Team
Registered: 2007-10-27
Posts: 1000+

Re: Use of variables

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.


http://i39.tinypic.com/2nav6o7.gif

Offline

 

#13 2010-02-25 09:37:03

Alec_2
Scratcher
Registered: 2010-02-24
Posts: 10

Re: Use of variables

Reply to fanofcena: no, I'm using a straight download/installation of the pre-build Scratch for MS Windows.

Offline

 

#14 2010-02-25 09:51:07

fanofcena
Scratcher
Registered: 2008-07-03
Posts: 1000+

Re: Use of variables

Hmm thats a bit new kinda problem and yeas Paddle2see has the best answer.


http://i53.tinypic.com/2vxr2c0.png Click whats above u might make a cute planet happy ^_^

Offline

 

#15 2010-02-25 10:07:45

Alec_2
Scratcher
Registered: 2010-02-24
Posts: 10

Re: Use of variables

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

 

#16 2010-02-25 22:24:33

billyedward
Scratcher
Registered: 2008-01-03
Posts: 500+

Re: Use of variables

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.


"I'd love to change the world, but they haven't released the source code yet."
Check out the latest version of Streak --> http://billy.scienceontheweb.net/Streak

Offline

 

#17 2010-02-26 05:33:59

Alec_2
Scratcher
Registered: 2010-02-24
Posts: 10

Re: Use of variables

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

 

#18 2010-02-28 00:08:34

billyedward
Scratcher
Registered: 2008-01-03
Posts: 500+

Re: Use of variables

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.


"I'd love to change the world, but they haven't released the source code yet."
Check out the latest version of Streak --> http://billy.scienceontheweb.net/Streak

Offline

 

#19 2010-02-28 03:32:04

urhungry
Scratcher
Registered: 2009-07-03
Posts: 1000+

Re: Use of variables

I'll try the script tommorrow. I don't think the os matters, but I'm running 64bit snow leapord. I have had trouble with this sort of thing too.

Offline

 

#20 2010-03-01 11:30:07

Alec_2
Scratcher
Registered: 2010-02-24
Posts: 10

Re: Use of variables

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

 

#21 2010-03-02 03:55:39

Paddle2See
Scratch Team
Registered: 2007-10-27
Posts: 1000+

Re: Use of variables

Closed by owner request.


http://i39.tinypic.com/2nav6o7.gif

Offline

 

Board footer