Getting a variable to equal any item in list

I have two lists here

untitled script pic (1)
untitled script pic

and this part of a script when the sprite hits something.

untitled script pic (2)

How would I go about making something happen when the "bounces" variable equals any value in the top list? The bottom list would correspond with the top list and show itself in a separate variable.

(There's an old tutorial that shows that the "item in list" block had the "any" option, but I think it has been replaced with the "random" option)

Here's what I would do

The asoc block is in the list utilities library (file > libraries > list utilities > import)

and if you want it to only run an action the first time, you'd just stick an if check around the set letter script

Here's another approach that you may or may not find helpful using a for loop. Basically you are always running the for loop and checking the item of each element in the list by index to see if the item equals bounces.

Running this for loop is a bit inefficient, since we have to go through every item each item we run these blocks. So minimize how many times we enter the for loop, we could add a condition, like this:

In this block, we are using item to keep track of the next greatest item in the list (the one we have not yet entered). So, we will only enter the for loop if bounces is greater than or equal to that item. Additionally, we are using the index variable to increment the items we are looping through the in the list - because if bounces is only at 2, we don't want to have to loop through all the other items since item are larger. Note, that both index and item would need to be made global variables not script variables for this to work. Personally, I think this block is a bit confusing and can be simplified and made cleaner and more concise.

Here is a cleaner more concise version using the repeat until block:


In this, we dont need to rely on extra looping and being inefficient and we also dont have to worry aobut creating additional global variables. (we do need to set index to an initial value though - which i forgot to do!)

hmm... can't we just check if the numbers list contains the bounces? My naive thinking would be that we don't need any loops or associations, something like this:

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.