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

#1 2012-01-28 18:32:40

coppearlix
Scratcher
Registered: 2010-01-31
Posts: 500+

Lists

In lists, you can add, delete, insert, replace.

But you can only do so at the first or last item on the list, or delete/replace all.

You can also use Operations to insert a number, and delete/insert/replace item 3, 4, or whatever.

However I think that there should be options for adding, deleting, inserting, and replacing named items, like "cheese," "cabbage," "sword." This would make inventories (for RPGs) a lot easier.


The Gobo has transformed--into the Gobony!
It's ALIIIIVE!

Offline

 

#2 2012-01-28 22:36:32

Chrischb
Scratcher
Registered: 2008-07-24
Posts: 1000+

Re: Lists

coppearlix wrote:

But you can only do so at the first or last item on the list, or delete/replace all.

I thought you could just enter in your own number :S


I fall: It's a tragedy. You fall: It's comedy.
Hmph enjoy your fall - I get a lovely spring... without pans of new leaves.

Offline

 

#3 2012-01-28 22:40:32

coppearlix
Scratcher
Registered: 2010-01-31
Posts: 500+

Re: Lists

Oh, right. Sorry, I was wrong about that. But you can't delete an object by its name.


The Gobo has transformed--into the Gobony!
It's ALIIIIVE!

Offline

 

#4 2012-01-28 23:50:42

Chrischb
Scratcher
Registered: 2008-07-24
Posts: 1000+

Re: Lists

tongue  And being able to delete an item by its name sounds nice :3


I fall: It's a tragedy. You fall: It's comedy.
Hmph enjoy your fall - I get a lovely spring... without pans of new leaves.

Offline

 

#5 2012-01-29 04:34:32

RedRocker227
Scratcher
Registered: 2011-10-26
Posts: 1000+

Re: Lists

coppearlix wrote:

Oh, right. Sorry, I was wrong about that. But you can't delete an object by its name.

Say you wanted to delete the item "Sword" in the list "Inventory". You'd put:

set [Temp1 v] to [1]
repeat until <<item (Temp1) of [Inventory v]> = <[Sword]>>
change (Temp1) by [1]
end
delete (Temp1) of [Inventory v]
It may be a little time consuming in big lists, but it works nonetheless.

Last edited by RedRocker227 (2012-01-29 04:44:45)


Why

Offline

 

#6 2012-01-29 07:03:03

rdococ
Scratcher
Registered: 2009-10-11
Posts: 1000+

Re: Lists

RedRocker227 wrote:

coppearlix wrote:

Oh, right. Sorry, I was wrong about that. But you can't delete an object by its name.

Say you wanted to delete the item "Sword" in the list "Inventory". You'd put:

set [Temp1 v] to [1]
repeat until <<item (Temp1) of [Inventory v]> = [Sword]>
change [Temp1 v] by [1]
end
delete (Temp1) of [Inventory v]
It may be a little time consuming in big lists, but it works nonetheless.

Fixed a bit.

Offline

 

#7 2012-01-29 16:42:13

Chrischb
Scratcher
Registered: 2008-07-24
Posts: 1000+

Re: Lists

RedRocker227 wrote:

coppearlix wrote:

Oh, right. Sorry, I was wrong about that. But you can't delete an object by its name.

Say you wanted to delete the item "Sword" in the list "Inventory". You'd put:

set [Temp1 v] to [1]
repeat until <<item (Temp1) of [Inventory v]> = <[Sword]>>
change (Temp1) by [1]
end
delete (Temp1) of [Inventory v]
It may be a little time consuming in big lists, but it works nonetheless.

I know that it can be done, but having a block to save time seems nice  hmm  Like how people want the previous costume block xD


I fall: It's a tragedy. You fall: It's comedy.
Hmph enjoy your fall - I get a lovely spring... without pans of new leaves.

Offline

 

#8 2012-01-29 21:05:36

coppearlix
Scratcher
Registered: 2010-01-31
Posts: 500+

Re: Lists

Thanks RedRocker227 and rdococ. I hadn't thought of that... Like Chrischb, I still think a block would save lots of time, but y'all have been a great help nonetheless. Hey, maybe I can make an RPG game now, and then I can finally delete that notification that's been bugging me for 9 months


The Gobo has transformed--into the Gobony!
It's ALIIIIVE!

Offline

 

#9 2012-01-29 21:56:46

MoreGamesNow
Scratcher
Registered: 2009-10-12
Posts: 1000+

Re: Lists

I believe you are talking about associative arrays.  I agree that these would be quite useful, but they would also over complicate arrays.  Unless you're assigning each item a number and a name, you'll have some elements with numbers, and some with names.  Giving all items both seems to over-complicate things (for instance, would "named" items be sorted alphabetically or by number?  Would "last item" be the last numbered item or the last named item?  etc.).  Just my two cents.


http://images2.layoutsparks.com/1/218929/rubiks-cube-animated-rotating.gif
"Cogito ergo sum" --  I think, therefore I am

Offline

 

#10 2012-01-29 22:07:20

coppearlix
Scratcher
Registered: 2010-01-31
Posts: 500+

Re: Lists

MoreGamesNow wrote:

I believe you are talking about associative arrays.  I agree that these would be quite useful, but they would also over complicate arrays.  Unless you're assigning each item a number and a name, you'll have some elements with numbers, and some with names.  Giving all items both seems to over-complicate things (for instance, would "named" items be sorted alphabetically or by number?  Would "last item" be the last numbered item or the last named item?  etc.).  Just my two cents.

?

Number refers to the item's position on the list... like this:

1. apple
2. warthog
3. pencil


The Gobo has transformed--into the Gobony!
It's ALIIIIVE!

Offline

 

#11 2012-01-29 22:21:59

MoreGamesNow
Scratcher
Registered: 2009-10-12
Posts: 1000+

Re: Lists

Sorry, I thought you were talking about associative arrays, but, after rereading the above comments, that was a mistake on my part.  If you're interested, an example would be:

[insert (6) at ("apple")]
[insert ("four") at ("pear")]

Creating this:

List:
apple    6
pear      "four"

Last edited by MoreGamesNow (2012-01-29 22:26:49)


http://images2.layoutsparks.com/1/218929/rubiks-cube-animated-rotating.gif
"Cogito ergo sum" --  I think, therefore I am

Offline

 

#12 2012-01-30 09:32:51

rdococ
Scratcher
Registered: 2009-10-11
Posts: 1000+

Re: Lists

MoreGamesNow wrote:

Sorry, I thought you were talking about associative arrays, but, after rereading the above comments, that was a mistake on my part.  If you're interested, an example would be:

[insert (6) at ("apple")]
[insert ("four") at ("pear")]

Creating this:

List:
apple    6
pear      "four"

You're still not getting it.

What the person wants is to remove named items on the list.
For an example:

List1:
1. apple
2. apple
3. pear
4. banana

Instead of having to check for which one is "pear", they could simply use:

delete [pear] of [List1 v]
and the first "pear" found is deleted.
In a different list that also contains "pear" in a different number than "3", the pear will be deleted, not whatever item is 3rd.

Offline

 

#13 2012-01-30 14:13:11

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

Re: Lists

rdococ wrote:

MoreGamesNow wrote:

Sorry, I thought you were talking about associative arrays, but, after rereading the above comments, that was a mistake on my part.  If you're interested, an example would be:

[insert (6) at ("apple")]
[insert ("four") at ("pear")]

Creating this:

List:
apple    6
pear      "four"

You're still not getting it.

What the person wants is to remove named items on the list.
For an example:

List1:
1. apple
2. apple
3. pear
4. banana

Instead of having to check for which one is "pear", they could simply use:

delete [pear] of [List1 v]
and the first "pear" found is deleted.
In a different list that also contains "pear" in a different number than "3", the pear will be deleted, not whatever item is 3rd.

He understood, he just wanted to make sure everyone knew what an associative array was.

Offline

 

Board footer