Discuss Scratch

savaka
Scratcher
1000+ posts

Position of item in list

(position of instance (1 v) of [hello] in [list v] :: list) // (number/dropdown also allows you to choose "last")
Sort of like indexOf in JavaScript but you can also choose what instance you want
Many suggestions people make for new list blocks would be very easily workarounable with this block

Last edited by savaka (Jan. 21, 2016 19:00:34)

BookOwl
Scratcher
1000+ posts

Position of item in list

Support, but I think that it should be renamed to
((1 v) index of [] in [list v] ::list)
savaka
Scratcher
1000+ posts

Position of item in list

BookOwl wrote:

Support, but I think that it should be renamed to
((1 v) index of [] in [list v] ::list)
Yeah my block is kind of long…
But in yours it doesn't really make sense what the number does
Failord
Scratcher
1000+ posts

Position of item in list

savaka wrote:

BookOwl wrote:

Support, but I think that it should be renamed to
((1 v) index of [] in [list v] ::list)
Yeah my block is kind of long…
But in yours it doesn't really make sense what the number does

How about:
(instance index (1 v) of [] in [list v] ::list)

Hmm… what we need is a concise, accurate, non-confusing phrasing.

Despite the existence of a workaround, I still support. After all, isn't
<[list v] contains [item]> // boolean
workaround-able? Hint: it is! Working around listy stuff is clunky and inefficient.

Last edited by Failord (Jan. 21, 2016 19:46:58)

little_kitten
Scratcher
500+ posts

Position of item in list

Support for instance index.
Sheep_tester
Scratcher
500+ posts

Position of item in list

Support, though I think it should be renamed to something shorter and more kid-friendly.
Also, I'm assuming it would return 0 if the list does not contain the string and I think it should just return the item number of the first matching item in the list.
Botcho_Otkho
Scratcher
1000+ posts

Position of item in list

Support! It would help on much cases, also because the workaround, even if it's simple, it takes much space and is a bit annoying to do that with command blocks and a variable that returns the position of the item.
position of first item [item] in list [list v]::list reporter
python_megapixel
Scratcher
500+ posts

Position of item in list

Support! I find it really annoying that you can't do this. You could probably work around it with a loop but that's complicated and inefficient/
TheGreatMelon
Scratcher
100+ posts

Position of item in list

If you made another list named for example, “clone” you could try this, since hidden lists can normally be looked through almost instantly:
find position of [] in list [list v]:: custom

define find position of [word] in list: Original List
delete (all v) of [clone v]
set [position v] to [1]
repeat (length of [Original List v]
insert (item (position) of [Original List v]) at (position) of [clone v]
change [position v] by (1)
end
set [position v] to [1]
repeat until <<(position) > (length of [clone v])> or <(item (position) of [clone v]) = (word)>>
change [position v] by (1)
end
set [position of word v] to (position)

In the end this variable
(position of word)
will be equal to the position of the word you are looking for.
You will to change the name of the custom block if you want it to make sense for your own list though.
Botcho_Otkho
Scratcher
1000+ posts

Position of item in list

TheGreatMelon wrote:

If you made another list named for example, “clone” you could try this, since hidden lists can normally be looked through almost instantly:
find position of [] in list [list v]:: custom

define find position of [word] in list: Original List
delete (all v) of [clone v]
set [position v] to [1]
repeat (length of [Original List v]
insert (item (position) of [Original List v]) at (position) of [clone v]
change [position v] by (1)
end
set [position v] to [1]
repeat until <<(position) > (length of [clone v])> or <(item (position) of [clone v]) = (word)>>
change [position v] by (1)
end
set [position of word v] to (position)

In the end this variable
(position of word)
will be equal to the position of the word you are looking for.
You will to change the name of the custom block if you want it to make sense for your own list though.
Why use a block and a variable just for one reporter?
medians
Scratcher
1000+ posts

Position of item in list

Bringing this up I guess because the block that now exists always gets the 1st, and I’ve seen this create confusion. It could also be a separate block that gets the last instead, and mentions that.
Maybe instead of a last option there could be a block counting how many times a string appears in a list? Though I have a workaround for that in a project, as well as a workaround for this block on an image.

Last edited by medians (July 15, 2023 21:47:28)

medians
Scratcher
1000+ posts

Position of item in list

Bringing this topic up.
No, this isn't completely implemented, read my last post.
medians
Scratcher
1000+ posts

Position of item in list

medians wrote:

Bringing this topic up.
No, this isn't completely implemented, read my last post.
medians
Scratcher
1000+ posts

Position of item in list

Bringing this topic up.
medians
Scratcher
1000+ posts

Position of item in list

medians wrote:

Bringing this topic up.

Powered by DjangoBB