This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2012-12-07 09:38:54

alperkow
New Scratcher
Registered: 2012-11-28
Posts: 2

Randomizing costumes in a Sprite

My small group is making a timed trivia game using Scratch. I'm the main programmer for our group. I've run into a big problem with my code that I have not been able to solve on my own.

In the game we have cards with questions on them. These cards are separated into different categories. So far my setup for this is to have a sprite for each category of questions and each costume be a different card. What I need to be able to do is randomize the order in which the cards appear each time the game is played. Not only do the cards need to be randomized but the code also needs to work in such a way that once a card appears it will not appear again.

So far I have been trying to accomplish this by using both the list and variable code. I have a list which keeps track of costume numbers that have yet to be used and another list that keeps track of what has been asked. I have one variable which is the random number I am trying to use to pick the costume and another variable which keeps track of how many cards have been picked.

The closest I have ever got to my code working was when it was able to go through the list of costumes yet to be used and chose them at random. However I could not stop it from reusing costumes. Another problem was that it would get stuck on the last item of the list and would not remove it.

I searched through the forum and found examples of using the randomize functions in Scratch and they have helped me get closer to my goal. However I have yet to find an example of randomizing the order of costumes in the sprite, which is essential to what I am doing. I have also been unable to find an example of stopping a costume from appearing after it has already been used.

Any help you can give me will be greatly appreciated. If you have an questions you would like to ask to clarify what I am trying to do please feel free to ask.

Offline

 

#2 2012-12-07 11:15:33

mythbusteranimator
Scratcher
Registered: 2012-02-28
Posts: 1000+

Re: Randomizing costumes in a Sprite

I'll post a pic...it would be easier.  smile


This is what I came up with (I used 5 cards as an example.)

http://i.imgur.com/M0rKO.gif


http://www.foxtrot.com/comics/2012-04-01-fdb37077.gif
clicky

Offline

 

#3 2012-12-07 11:47:39

BetaSmozzick
Scratcher
Registered: 2012-02-25
Posts: 51

Re: Randomizing costumes in a Sprite

If I understand this then this should work:

Make 2 lists. One list will contain a full list of costumes for the sprite. The other initially fills with that list but each time a card is drawn the costume will be changed and that costume will be removed from the list so that it cannot be chosen again in the future.

Offline

 

#4 2012-12-07 20:32:49

alperkow
New Scratcher
Registered: 2012-11-28
Posts: 2

Re: Randomizing costumes in a Sprite

mythbusteranimator - I can't seem to get this code to change the costume of the Sprite. Also (I ended up having to put a few 'wait 1 second' to see it do this) it is initially putting all the questions in the list. Then the very last thing the code will do is delete one of the questions on the list.

BetaSmozzick - that sounds pretty close to what I'm trying to do. However, in practice I find my code has some strange bugs. One of the biggest issues is the code would not remove the last item in the list that originally contained all the sprites. It would either get caught in an infinite loop or I would have to force it to start with one question unasked. It would also repeat questions and I couldn't get that to stop.

Offline

 

#5 2012-12-07 21:21:47

BurritoSM
Scratcher
Registered: 2012-11-11
Posts: 33

Re: Randomizing costumes in a Sprite

mythbusteranimator wrote:

I'll post a pic...it would be easier.  smile


This is what I came up with (I used 5 cards as an example.)

I believe that you meant to, instead of joining the chosen number with costume, to just set it to that particular number chosen.

Offline

 

Board footer