Discuss Scratch

Miss_Jude
New to Scratch
10 posts

How to make different sprites be shown randomly one at a time in the same position

Hi,

I'm new on Scratch… I'm trying to make this project where my students classify food into countable and/or uncountable categories. I have two sprites with several costumes each (one for countable the other for uncountable nouns). They are shown in the middle of the backdrop and they have to be dragged towards the corresponding box. The thing is that I do not know how to make these two objects appear randomly (in that same position -centre) one at a time, wait till it is classified and show the next one. Be it countable or uncountable…. Am I clear? Well, thanks in advance.

Jude
ArukRajared
Scratcher
6 posts

How to make different sprites be shown randomly one at a time in the same position

Hey Miss_Jude

Without looking at the exact program it may be hard to give you a definite answer. However, if in your individual sprite you have a script like this it should work. The simplest method would be to create a variable that randomly chooses between one and two:
set [Variable] to (pick random (1) to (2))
Then you can set sprite one to appear only when variable=1
when green flag clicked
forever
if <(variable) = [1]> then


switch costume to (pick random (firstcostume#) to (lastcostume#))
show

else
hide
end
end
However this would most easily be achieved by creating a clone every time one is classified. (You can do this by broadcasting an event when something is correctly classified.) Then follow the script above. In order to only have them appear one at a time you can create a list and have an item added to that list when it is correctly classified. Then have the switch costume option check to see if the item is not in the list before choosing it. This may require an extra variable but the basic script could look like this:
if <not <[list] contains [thing] ?>> then

end
Did I answer your question?

ArukRajared

Last edited by ArukRajared (June 5, 2018 22:40:35)


ArukRajared
Miss_Jude
New to Scratch
10 posts

How to make different sprites be shown randomly one at a time in the same position

Thanks, Aruk. I've tried following your directions but I still find it hard to make it work. I'll see if I can find some other solution to my problem. Thanks all the same.
Miss_Jude
New to Scratch
10 posts

How to make different sprites be shown randomly one at a time in the same position

Here's the link, if you wanna have a look at it.

https://scratch.mit.edu/projects/225418954/#editor
deck26
Scratcher
1000+ posts

How to make different sprites be shown randomly one at a time in the same position

You essentially just need a variable to keep track of the current state.

For example, let's say the variable ‘state’ has the following possible values

0 - nothing selected so ready for the next item
1 - current item is type A
2 - current item is type B

This variable can be used with a broadcast to show a random item from one of the two categories and to check whether it was dragged to the right place. Once it has been dealt with you set the variable to 0 and you have a game control loop which waits for that before resetting the variable to 1 or 2 at random.

So a simple game loop in pseudo code

repeat (n)
set state to random 1 to 2
broadcast show-item
wait until state = 0
end
deck26
Scratcher
1000+ posts

How to make different sprites be shown randomly one at a time in the same position

Miss_Jude wrote:

Here's the link, if you wanna have a look at it.

https://scratch.mit.edu/projects/225418954/#editor
Not shared
SuperSquidXX
Scratcher
30 posts

How to make different sprites be shown randomly one at a time in the same position

If this is what you mean:
go to x: (0) y: (0)
forever
switch costume to (pick random (1) to (10))
wait (1) secs
end

Last edited by SuperSquidXX (June 9, 2018 11:45:21)

SuperSquidXX
Scratcher
30 posts

How to make different sprites be shown randomly one at a time in the same position

SuperSquidXX wrote:

If this is what you mean:
go to x: (0) y: (0)
forever
switch costume to (pick random (1) to (10))
wait (1) secs
end
or:
forever
if <key [space] pressed?> then
switch costume to (pick random (1) to (5))
wait until <not <key [space] pressed?>>
end

end
Miss_Jude
New to Scratch
10 posts

How to make different sprites be shown randomly one at a time in the same position

Thanks, everyone, but I still can't make it work.
gor-dee
Scratcher
1000+ posts

How to make different sprites be shown randomly one at a time in the same position

I looked at your scripts and I think the following should work…

create a global variable “foodType”
in apple sprite only put
set [foodType v] to (pick random (0) to (1))
under the green flag
put
if <(foodType) = [1]> then 


show

else
hide
end
inside the forever loop and put the same in the Glass water sprite but foodType=0

then replace all the
show
blocks at the end of the IFs in both sprites with
set [foodType v] to (pick random (0) to (1))
then I think it will work!
Miss_Jude
New to Scratch
10 posts

How to make different sprites be shown randomly one at a time in the same position

Many thanks, gor-dee. I've tried with your suggestion but it doesn't work either. I was thinking about using only one sprite with 10 costumes and setting costumes 1-5 to be countable and 6-10, uncountable. But… I couldn't make it work properly. I'm getting frustrated here…
PutneyCat
Scratcher
500+ posts

How to make different sprites be shown randomly one at a time in the same position

Your food sprites seem to be too big. As soon as they appear, they are touching the countable/uncountable boxes.

Try putting “set size to 50%” under the green flag for the food sprites.
gor-dee
Scratcher
1000+ posts

How to make different sprites be shown randomly one at a time in the same position

Yes @PutneyCat is right (I can see now you have shared the project!). My suggestion above will stop both the sprites appearing together
Miss_Jude
New to Scratch
10 posts

How to make different sprites be shown randomly one at a time in the same position

They started to get bigger and bigger with all the modifications. At first, they were all the same size and waited for commands, to be dragged before disappearing.
deck26
Scratcher
1000+ posts

How to make different sprites be shown randomly one at a time in the same position

Miss_Jude wrote:

They started to get bigger and bigger with all the modifications. At first, they were all the same size and waited for commands, to be dragged before disappearing.
The size shouldn't change unless you tell it to - did you perhaps have a change size by block in there earlier? Try adding a set size to 50% (or whatever) to the sprite's green flag script.
gor-dee
Scratcher
1000+ posts

How to make different sprites be shown randomly one at a time in the same position

You've unshared the project again so we can't try it but I can see your scripts and I see you've put all the costumes into one sprite now. This is ok but where you have IF (costume#) = pick random 1-5 you should have IF (costume#) < 6 and where you have IF (costume#) = pick random 6-10 you should have IF (costume#) > 5
I can't see anything that would make the costumes change size though
Miss_Jude
New to Scratch
10 posts

How to make different sprites be shown randomly one at a time in the same position

Yes! I decided to unshare it till it is finished. I think I'm going on the right track thanks to your comments… now, I'm trying to change costumes randomly but without repeating them. I created a list, but they still get repeated.
gor-dee
Scratcher
1000+ posts

How to make different sprites be shown randomly one at a time in the same position

It might be easier to delete the list at the beginning and add to it each time a costume is picked, then you can check if a costume is already in the list.
So
delete ( all v) of [list v]
add (costume #) to [list v]
under the green flag
Then instead of the four “switch costume to (pick random)”, have
repeat until <not <[list v] contains (costume #) ?>>
switch costume to (pick random (1) to (10))
end
add (costume #) to [list v]
You also still have the issue I mentioned in my previous comment, so that needs fixing…

EDIT: I've just tried this and it's better if you have
add (costume #) to [list v]
repeat until <not <[list v] contains (costume #) ?>>
switch costume to (pick random (1) to (10))
end
in the correct answer IFs, and
switch costume to (pick random (1) to (10)) 
repeat until <not <[list v] contains (costume #) ?>>
switch costume to (pick random (1) to (10))
end
in the wrong answer IFs.

and remove the
add (costume #) to [list v]
from under the green flag.

This way if you get an answer wrong, the item isn't added to the list (which contains correct answers only), so you get another go at it.

Also it was a bit giltchy when I tried, sometimes counting twice. to cure this put
wait until <mouse down?>
wait until <not <mouse down?>>
as the first thing in the forever loop

Last edited by gor-dee (June 15, 2018 11:45:56)

Miss_Jude
New to Scratch
10 posts

How to make different sprites be shown randomly one at a time in the same position

Thank you for your selfess help. Very kind of you all.
Bryan007
Scratcher
100+ posts

How to make different sprites be shown randomly one at a time in the same position

Miss_Jude wrote:

Thank you for your selfless help. Very kind of you all.
Your welcome although I didn't help

quit w

i'll probably only check my scratch account every year or two. if you want to leave me a message, feel free to drop it in my comments, under my profile.

Powered by DjangoBB