Discuss Scratch
- TheGuyWithTheHat2
-
33 posts
Block Idea: Place of [word] in [list]
(place of [thing] in [list v]::list)I don't know why this block doesn't exist yet. It's MUCH easier than making a bunch of blocks to scan through a list.
“Oh what if there isn't any of it in the list”
Two solutions.
if <[vegetables v] contains [apple ]> then
do whatever to (place of [apple] in [vegetables v]::list)
end
or
< (place of [apple] in [vegetables v]::list) = [0]>
I'm not a programming language programmer so I don't know if you can or can't do this, but I think you'd have a block like this by now.
THE END
Last edited by TheGuyWithTheHat2 (Dec. 9, 2014 21:48:14)
- Zro716
-
1000+ posts
Block Idea: Place of [word] in [list]
add [thing] to [list v]now what
add [thing] to [list v]
add [thing] to [list v]
add [thing] to [list v]
set [index v] to (place of [thing] in [list v] ::list)
- djdolphin
-
1000+ posts
Block Idea: Place of [word] in [list]
Average them - 2.5add [thing] to [list v]now what
add [thing] to [list v]
add [thing] to [list v]
add [thing] to [list v]
set [index v] to (place of [thing] in [list v] ::list)
jk
- ChocolatePi
-
1000+ posts
Block Idea: Place of [word] in [list]
add [thing] to [list v]
add [thing] to [list v]
add [thing] to [list v]
add [thing] to [list v]
set [index v] ((1st v) occurrence of [thing] in [list v] :: list) :: variables
set [index v] ((last v) occurrence of [thing] in [list v] :: list) :: variables
I've actually wanted this
Last edited by ChocolatePi (Dec. 9, 2014 22:52:24)
- stickfiregames
-
1000+ posts
Block Idea: Place of [word] in [list]
Support, it would be useful for indexing lists.
- TheGuyWithTheHat2
-
33 posts
Block Idea: Place of [word] in [list]
add [thing] to [list v]now what
add [thing] to [list v]
add [thing] to [list v]
add [thing] to [list v]
set [index v] to (place of [thing] in [list v] ::list)
Hmmmmm
I guess the first one, unless you use the block ChocolatePi made
What other problems could that come across? I know you guys love finding those in your free time
- Cyoce
-
500+ posts
Block Idea: Place of [word] in [list]
Support. This would make creating “project cookies” (data that is specific to a user for that project, e.g. highscores) much easier.
Last edited by Cyoce (Dec. 10, 2014 00:19:24)
- MegaApuTurkUltra
-
1000+ posts
Block Idea: Place of [word] in [list]
It would return the first index where it was found. I mean, that's how things like JavaScript arrays work.add [thing] to [list v]now what
add [thing] to [list v]
add [thing] to [list v]
add [thing] to [list v]
set [index v] to (place of [thing] in [list v] ::list)
Support for this
- Cyoce
-
500+ posts
Block Idea: Place of [word] in [list]
So how aboutIt would return the first index where it was found. I mean, that's how things like JavaScript arrays work.add [thing] to [list v]now what
add [thing] to [list v]
add [thing] to [list v]
add [thing] to [list v]
set [index v] to (place of [thing] in [list v] ::list)
Support for this
(first occurence of [thing] in [list v] :: list)To avoid confusing people?
Last edited by Cyoce (Dec. 10, 2014 23:13:59)
- ChocolatePi
-
1000+ posts
Block Idea: Place of [word] in [list]
what about mine?So how aboutIt would return the first index where it was found. I mean, that's how things like JavaScript arrays work.add [thing] to [list v]now what
add [thing] to [list v]
add [thing] to [list v]
add [thing] to [list v]
set [index v] to (place of [thing] in [list v] ::list)
Support for thisfirst occurence of [thing] in [list v] :: listTo avoid confusing people?
add [thing] to [list v]
add [thing] to [list v]
add [thing] to [list v]
add [thing] to [list v]
set [index v] ((1st v) occurrence of [thing] in [list v] :: list) :: variables
set [index v] ((last v) occurrence of [thing] in [list v] :: list) :: variables
I've actually wanted this
- Cyoce
-
500+ posts
Block Idea: Place of [word] in [list]
I like yours better, but my suggestion was just to clarify the block he was creating.what about mine?So how aboutIt would return the first index where it was found. I mean, that's how things like JavaScript arrays work.add [thing] to [list v]now what
add [thing] to [list v]
add [thing] to [list v]
add [thing] to [list v]
set [index v] to (place of [thing] in [list v] ::list)
Support for this(first occurence of [thing] in [list v] :: list)To avoid confusing people?add [thing] to [list v]
add [thing] to [list v]
add [thing] to [list v]
add [thing] to [list v]
set [index v] ((1st v) occurrence of [thing] in [list v] :: list) :: variables
set [index v] ((last v) occurrence of [thing] in [list v] :: list) :: variables
I've actually wanted this
I would prefer yours, but if the block were to simply return the first one, it should be named as such.
- Alberknyis
-
1000+ posts
Block Idea: Place of [word] in [list]
add [thing] to [list v]now what
add [thing] to [list v]
add [thing] to [list v]
add [thing] to [list v]
set [index v] to (place of [thing] in [list v] ::list)
1.
Or zero if you do python/other languages that I don't know about
- theonlygusti
-
1000+ posts
Block Idea: Place of [word] in [list]
You meant bad languages.add [thing] to [list v]now what
add [thing] to [list v]
add [thing] to [list v]
add [thing] to [list v]
set [index v] to (place of [thing] in [list v] ::list)
1.
Or zero if you do python/other languages that I don't know about
- Prinseskat
-
1000+ posts
Block Idea: Place of [word] in [list]
Support this!add [thing] to [list v]
add [thing] to [list v]
add [thing] to [list v]
add [thing] to [list v]
set [index v] ((1st v) occurrence of [thing] in [list v] :: list) :: variables
set [index v] ((last v) occurrence of [thing] in [list v] :: list) :: variables
I've actually wanted this
- Alberknyis
-
1000+ posts
Block Idea: Place of [word] in [list]
You meant bad languages.add [thing] to [list v]now what
add [thing] to [list v]
add [thing] to [list v]
add [thing] to [list v]
set [index v] to (place of [thing] in [list v] ::list)
1.
Or zero if you do python/other languages that I don't know about
No, I meant other languages.
- rollercoasterfan
-
1000+ posts
Block Idea: Place of [word] in [list]
Support for
((1st v) occurence of [thing] in [list v] ::list)
((last v) occurence of [thing] in [list v] ::list)
- monstermash3
-
1000+ posts
Block Idea: Place of [word] in [list]
Support! In fact, I've been REALLY wishing there was a
But I agree with rollercoasterfan's idea:
This is workaroundable, however.
For example,
delete all occurrences of [thing] in [list v]::listfor a while.
But I agree with rollercoasterfan's idea:
since it wouldn't work if there was more than one occurence. Support for((1st v) occurence of [thing] in [list v] ::list)
((last v) occurence of [thing] in [list v] ::list)
This is workaroundable, however.
(occurence (2 v) of [thing] in [list v] ::list)would be workaroundable as follows.
For example,
say (join [The second occurrence of the string "thing" in the list is item ] (join (occurrence (2 v) of [thing] in [list v]::list) [.])would be
set [item v] to [1]But that workaround is not that easy, so I still support.
set [occurrences v] to [0]
repeat until <(occurrences) = [2]>
if <(item (item) of [list v]) = [thing]> then
change [occurrences v] by [1]
end
change [item v] by [1]
end
say (join [The second occurrence of the string "thing" in the list is item ] (join ((item) - (1)) [.])
Last edited by monstermash3 (July 27, 2015 00:23:35)