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

#1 2011-08-17 17:57:55

Germanium_Tinide
New Scratcher
Registered: 2011-01-11
Posts: 39

A Problem with using Lists...

I have noticed, that the [ersetze (x) Element von [Liste] durch (y)] block ("replace item (x) of [List] with (y)") works only when there already are x Elements in the List...  sad

Is there a Way to bypass this Problem (for example, if I want to set Item 2 to something regardless of whether or not it is there already), without using a long if-else Sequence or adding x Items and then deleting them after the Replacement)? Both of those Alternatives are tedious and do not always work...  hmm

There are some other Problems with Lists too... I will talk about them later.

Offline

 

#2 2011-08-17 18:19:24

Harakou
Community Moderator
Registered: 2009-10-11
Posts: 1000+

Re: A Problem with using Lists...

Do you mean like a list has to be at least x items long for the "replace item x" block to work? Yes, I suppose that could be a problem.

You could use a loop to check if the list is x long and add items until it is, but you don't seem to want to do that. Other than that I see no way to do it though.  hmm

Code:

Hat block of choice
other code
if (length of list y < x)
    repeat until (length of list y = x)
        add "null" to list y
replace item x of list y with z

http://www.blocks.scratchr.org/API.php?action=random&amp;return=image&amp;link1=http://i.imgur.com/OZn2RD3.png&amp;link2=http://i.imgur.com/duzaGTB.png&amp;link3=http://i.imgur.com/CrDGvvZ.png&amp;link4=http://i.imgur.com/POEpQyZ.png&amp;link5=http://i.imgur.com/ZKJF8ac.png

Offline

 

Board footer