Say I have a list called 'colours' that is filled randomly with colours resulting in
colours[1] = Blue
colours[2] = Red
colours[3] = Yellow
How do I remove a specific item from the list, e.g. the colour Red, when I don´t know its index?
This run it is item #2, but maybe next run it is item #3, or #8.
Thanks in advance,
Roger.
Offline
Use the (delete 1 of [colors]) block. Highlight the 1 and change it to any number.
Offline
Lellowsfuzz wrote:
Use the (delete 1 of [colors]) block. Highlight the 1 and change it to any number.
He means that the position of the color changes and the project needs to be able to find it.
The best way would be create a variable called "listchecker" and use a script like this:
set [listchecker] to (1)
repeat until <(item (listchecker) of [colors])) = [yellow]>
change [listchecker] by (1)
[end of loop]
delete item (listchecker) of [colors]
This would search the list for an item called "yellow" (you can change that to any color you want), and deletes it after it finds it. Just note that the "repeat until" block is kind of slow by default, so try not to use it when you need it to work really fast.
Last edited by hmnwilson (2010-08-08 12:52:45)
Offline
hmnwilson wrote:
set [listchecker] to (1)
repeat until <(item (listchecker) of [colors])) = [yellow]>
change [listchecker] by (1)
[end of loop]
delete item (listchecker) of [colors]
This would search the list for an item called "yellow" (you can change that to any color you want), and deletes it after it finds it. Just note that the "repeat until" block is kind of slow by default, so try not to use it when you need it to work really fast.
Thanks,
I thought of this just after posting. What I'm really trying is to create a bingo game.
I filled one list (drawable_balls) with incrementing integers, e.g. (1, 2, 3, 4, 5).
I'd like to pick randomly one integer out of that list and move it to another list (drawn_balls).
It's a pity that this doesn't work:
repeat until <length of {drawable_balls}> = 0 ..set [ball] to <item[any]> of {drawable_balls} ..add [ball] to {drawn_balls} ..delete [ball] of {drawable_balls}
The lists' delete method only works using indices, not objects, if I understand correctly.
So what I ended up with is creating a help variable random_index:
repeat until <length of {drawable_balls}> = 0 ..set [random_index] to (pick random 1 to (length of {drawable_balls})) ..set [ball] to <item[random_index]> of {drawable_balls} ..add [ball] to {drawn_balls} ..delete [random_index] of {drawable_balls}
Thanks for your reactions,
Roger
Offline