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

#1 2009-01-03 02:09:45

markyiscool
Scratcher
Registered: 2008-04-09
Posts: 100+

Sum of list

I was wondering if there is an easy way to add the sum off all items in a list


Wanted the Netherlands to win or want to re-experience Spain's victory? Do it withthis!
Projects not being loved, here's an idea!

Offline

 

#2 2009-01-03 06:58:32

Dan01
Scratcher
Registered: 2008-06-11
Posts: 100+

Re: Sum of list

You could quite easliy.

First make two variables, any names will do. For the example I'll call one "#" and one "total".

Then you want to set up a simple script like this:

<set{ # }to( 1 )
<repeat( length of list )
<change{ total }by( number { # } of list
<change{ # }by( 1 )
<end>

(Sorry if it's a bit hard to understand > The scratch team haven't updated the blocks to include lists yet.)

This is simply saying, set the # variable to 1 and then change the total variable by the number on the variable # of the list and then changing the # variable by 1.

I hope that helps  smile


http://img3.imageshack.us/img3/4743/ubd6522wp8.png
http://img3.imageshack.us/img3/4667/ubd3758ox2.png

Offline

 

#3 2009-01-03 07:02:41

Dan01
Scratcher
Registered: 2008-06-11
Posts: 100+

Re: Sum of list

Here is a project which explains it clearer:

http://scratch.mit.edu/projects/Dan_Test/369914


http://img3.imageshack.us/img3/4743/ubd6522wp8.png
http://img3.imageshack.us/img3/4667/ubd3758ox2.png

Offline

 

#4 2009-01-03 12:38:08

bhz
Scratcher
Registered: 2008-07-06
Posts: 100+

Re: Sum of list

I've added the ability to sum all the #s of a list to my project with a LOT of math functions

Offline

 

Board footer