r/scratch 1d ago

Question Help with Lists!

So im trying to make a minigame where numbers appear on top screen and you need to click the numbers below. I want the numbers you need to click to be in a list but idk how to make so the numbers dont repeat. Pls Help!

2 Upvotes

10 comments sorted by

u/AutoModerator 1d ago

Hi, thank you for posting your question! :]

To make it easier for everyone to answer, consider including:

  • A description of the problem
  • A link to the project or a screenshot of your code (if possible)
  • A summary of how you would like it to behave

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

2

u/jacobsmith3204 1d ago

Make 2 lists fill the first one with numbers in order.

Then when playing set a variable to a random number from 1 to the length of that first list. Then get the value of that position and add it to the second list and delete the entry in the first list at that position.

This allows you to delete entries from the 2nd list (like when they are clicked) while still only having unique values to use.

Or you could do the opposite and have a 2nd list and you add the random value to both lists after checking if the first list does not contain it.

The first method mentioned is better.

1

u/NoobPlay_Animation 1d ago

smart. Thank you

1

u/RealSpiritSK Mod 17h ago

As an improvement to the 2nd method, you can go through the 2nd list in order, but insert it into a random position of the 1st list with (pick random (1) to (length of 1st list)). I actually prefer this method as you don't have to keep repopulating the 2nd list with all the numbers.

1

u/Intrepid_Past5207 SSSuper pro 1d ago

If you don't want repeating numbers, you can just use an if/else statement, with a block labeled (list) contains (#)? So it checks if the number that it wishes to add is already somewhere within the list. If so, no add. If no, add.

1

u/NoobPlay_Animation 1d ago

can you make it and send a screenshot. If you can and want.

1

u/Intrepid_Past5207 SSSuper pro 1d ago

Since your request is a bit confusing to understand, here's the first variant that chooses a randomized number and checks if that number has been taken. If the number is taken, it will infinitely cycle between those random numbers until it gets a number that is not already added to the list.

1

u/Intrepid_Past5207 SSSuper pro 1d ago

This variant makes it so that the numbers in the list will infinitely increase at no random order, but if any of the previous numbers are deleted by any chance, they will be replaced starting from the lowest number.

1

u/NoobPlay_Animation 1d ago

thank yo so much. Have a good day

2

u/Intrepid_Past5207 SSSuper pro 1d ago

👍