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

#1 2012-04-24 12:23:20

s_federici
Scratcher
Registered: 2007-12-18
Posts: 500+

"insert at" in lists is broken

After a fair amount of tests, it seems to me that the "any" option in the "insert at" block of the Variables category, will never match the "last" position in the list.

If this is true, after using a sequence of "any"s, the very *first* item added to the list will always be the *last one*. This is contrary to the random nature of the "any" list position.

The behavour is different in Scratch 1.4/2.0/Flash Player/Java Player. Try it yourself with the "first is last" project.

Last edited by s_federici (2012-05-29 03:26:11)

Offline

 

#2 2012-04-24 12:32:09

LS97
Scratcher
Registered: 2009-06-14
Posts: 1000+

Re: "insert at" in lists is broken

You are completely right -- after adding 1500 elements to a list I made in Scratch, the first item (which I had named separately to test it out) was still at the bottom.

I can understand how this has been such an easy error, since the list entry argument is used in many other list blocks and is needed, in those cases, to return a valid item in the list.

The correct way to approach the random inserting would be

insert [x] at (pick random (1) to ((length of [list v]) + (1))) of [list v]

Last edited by LS97 (2012-04-24 12:32:45)

Offline

 

#3 2012-04-26 10:48:58

s_federici
Scratcher
Registered: 2007-12-18
Posts: 500+

Re: "insert at" in lists is broken

LS97 wrote:

The correct way to approach the random inserting would be

insert [x] at (pick random (1) to ((length of [list v]) + (1))) of [list v]

Yes, exactly, this is one of the scripts I started using instead of the simple "any".

LS97 wrote:

the first item (which I had named separately to test it out) was still at the bottom.

To keep the scripts (for my students) simple I use indeed a dummy final element. I add it first. Then I use all "any inserted" elements except the very last (dummy) one.

But I'd like a lot to be able to use "any" instead.

Offline

 

#4 2012-04-26 11:35:27

LS97
Scratcher
Registered: 2009-06-14
Posts: 1000+

Re: "insert at" in lists is broken

It's worth remembering that if the list adding is a one-time process, the dummy can be added and the beginning and deleted at the end, so that you can use the simple "any" block to access a random element of the list!  smile

Offline

 

#5 2012-05-28 10:58:12

3sal2
Scratcher
Registered: 2012-03-22
Posts: 100+

Re: "insert at" in lists is broken

The any drop down works on my computer. What computer do you use? I use a Mac OS X.


http://scratch.mit.edu/static/projects/3sal2/3120946_sm.png In 2012, scientists at the LHC discovered the Higgs boson, which explains the source of the masses of the W+, W-, and Z bosons, as well as fermions.

Offline

 

#6 2012-05-28 13:40:29

scimonster
Community Moderator
Registered: 2010-06-13
Posts: 1000+

Re: "insert at" in lists is broken

3sal2 wrote:

The any drop down works on my computer. What computer do you use? I use a Mac OS X.

It's not the dropdown broken, but rather the feature itself. Did you try the experiment above?

Offline

 

#7 2012-05-28 14:08:10

SciTecCf
Scratcher
Registered: 2011-11-23
Posts: 1000+

Re: "insert at" in lists is broken

I tried the experiment and it worked fine. My separately named item was at number 39 of a 72 item long list.


http://bit.ly/LCZEJRhttp://bit.ly/LSONcOhttp://bit.ly/LF3vIc
http://trinary.site40.net/images/scratchrank.php?username=SciTecCf&display=small

Offline

 

#8 2012-05-28 17:52:08

ManaUser
Scratcher
Registered: 2009-03-11
Posts: 100+

Re: "insert at" in lists is broken

I think arguably this is correct, because putting it at the end isn't really "inserting". However, both the Flash and Java players give the expected result, which might be a sign that the behavior you described was not intended.

Last edited by ManaUser (2012-05-28 17:52:31)


http://i.imgur.com/SPYSM.gif http://i.imgur.com/t9k1Z.gif http://i.imgur.com/OwYVa.gif http://i.imgur.com/0qlZq.gif

Offline

 

#9 2012-05-29 03:23:34

s_federici
Scratcher
Registered: 2007-12-18
Posts: 500+

Re: "insert at" in lists is broken

ManaUser wrote:

However, both the Flash and Java players give the expected result, which might be a sign that the behavior you described was not intended.

I tested it with the "first is last" project, and this is not always the case. As  matter of fact, the players (and Scratch 2.0) are more stable, but not completely correct. Instead 1.4 is strictly consistent

Offline

 

Board footer