Discuss Scratch

22ertyu
New to Scratch
28 posts

Drag and Drop: Shopping Game

Hi, I'm new to Scratch and really need your guys' help.
I'm trying to make a shopping game where the items are on the shelf and the stock number is below the item.
When the player wants an item they are to drag the item into the nearby “cart” sprite.
What I want to happen is that the stock number goes down (Got that part) and the item is still there even though it was dragged to the cart.
To do that second part, I made the item make a clone of itself and go to where the original item used to be and if the player wants another of that item then that clone will clone itself and the user would be dragging the original clone.
I want all that to continue in a loop until Stock=0. When Stock=0 I want the item to not be draggable anymore. I tried doing the toggle method, where I put “if dragging=0..” or “if dragging=1” but it's not working!
Please help!!! I'd really appreciate it!
scrooge100
Scratcher
1000+ posts

Drag and Drop: Shopping Game

Can you share the project?

22ertyu
New to Scratch
28 posts

Drag and Drop: Shopping Game

Yeah here's the link: Your text to link here…
I just want it so that if they take out 3 of the item then 3 will be in the cart and the thing will stop cloning and instead leave the shelf blank. Please tell me if I should change anything or if I can improve it. Thank youuuuu
22ertyu
New to Scratch
28 posts

Drag and Drop: Shopping Game

Yeah here it is: computer store
I just want the item to not appear on the shelf when the stock is 0 and I want there to be 3 visible items in the cart. Please tell me if I can improve the code and thank youuuu
deck26
Scratcher
1000+ posts

Drag and Drop: Shopping Game

If the cart doesn't move with the objects inside you could try creating a clone when the item is selected and stamping it when it is in the cart so you can delete the clone. That helps avoid problems with clones responding to the when sprite clicked hat block as well as the sprite doing so. Alternatively give clones a cloneID of 1 while keeping the sprite as cloneID=0 so you can, again, only drag a newly created clone and only the sprite creates clones. If you do that it shouldn't be difficult to hide the sprite when the stock is 0 so it can't be dragged.
asivi
Scratcher
1000+ posts

Drag and Drop: Shopping Game

Tested scripts, the sprite doesn't need to be draggable
when flag clicked
clear
hide
go to x:(30) y:(105)
set [Stock v] to [3]
hide variable [Stock v]


when backdrop switches to [SOFTWARE v]
clear
show
go to x:(43) y:(101)
show variable [Stock v]
forever
if <(Stock) = [0]> then
hide
stop [this script v]
end
end


when I receive [decrease Stock soft1 v]
change [Stock v] by (-1)


when this sprite clicked
create clone of [myself v]


when I start as a clone
go to front
show
repeat until <not <mouse down?>>
go to [mouse-pointer v]
end
if <<(x position) < [-40]> and <(y position) < [-30]>> then
broadcast [decrease Stock soft1 v]
go to x:(pick random (-120) to (-60)) y:(-90)
stamp
delete this clone
end
delete this clone


when backdrop switches to [storage & software v]
clear
hide
hide variable [Stock v]
stop [other scripts in sprite v]


when backdrop switches to [CHECK-OUT v]
clear
hide
hide variable [Stock v]
stop [other scripts in sprite v]

Last edited by asivi (April 16, 2016 10:36:29)

22ertyu
New to Scratch
28 posts

Drag and Drop: Shopping Game

asivi wrote:

Tested scripts, the sprite doesn't need to be draggable
when flag clicked
clear
hide
go to x:(30) y:(105)
set [Stock v] to [3]
hide variable [Stock v]


when backdrop switches to [SOFTWARE v]
clear
show
go to x:(43) y:(101)
show variable [Stock v]
forever
if <(Stock) = [0]> then
hide
stop [this script v]
end
end


when I receive [decrease Stock soft1 v]
change [Stock v] by (-1)


when this sprite clicked
create clone of [myself v]


when I start as a clone
go to front
show
repeat until <not <mouse down?>>
go to [mouse-pointer v]
end
if <<(x position) < [-40]> and <(y position) < [-30]>> then
broadcast [decrease Stock soft1 v]
go to x:(pick random (-120) to (-60)) y:(-90)
stamp
delete this clone
end
delete this clone


when backdrop switches to [storage & software v]
clear
hide
hide variable [Stock v]
stop [other scripts in sprite v]


when backdrop switches to [CHECK-OUT v]
clear
hide
hide variable [Stock v]
stop [other scripts in sprite v]

Wow thanks for the code!!!

But, is it possible to work around the ‘stop’ blocks? and I want it so that when the user long presses the item it'll be draggable, but when they just click it once, this sprite will pop up which tells you info about the sprite. That's why I have:

when this sprite clicked
broadcast [ software1 v]


so that the info sprite will show
Andddd when you stamp, is it possible to replace the stamped sprite with another new sprite which is a grey square that sits at the bottom, inside the cart?
I would use something like ‘if touching cart then broadcast….and clear’ The broadcast is for the grey box to show up right?

Last edited by 22ertyu (April 16, 2016 11:32:35)

22ertyu
New to Scratch
28 posts

Drag and Drop: Shopping Game

deck26 wrote:

If the cart doesn't move with the objects inside you could try creating a clone when the item is selected and stamping it when it is in the cart so you can delete the clone. That helps avoid problems with clones responding to the when sprite clicked hat block as well as the sprite doing so. Alternatively give clones a cloneID of 1 while keeping the sprite as cloneID=0 so you can, again, only drag a newly created clone and only the sprite creates clones. If you do that it shouldn't be difficult to hide the sprite when the stock is 0 so it can't be dragged.
Hi thanks for replying! I have another question: Would the clone have the same commands as the original sprite or would it just be setting its cloneID to 1?…and the items in the cart do have to move with the cart…like each time I go to a different shelf, the clones (or the grey square boxes talked about below) should be viewed in the cart.
22ertyu
New to Scratch
28 posts

Drag and Drop: Shopping Game

22ertyu wrote:

deck26 wrote:

If the cart doesn't move with the objects inside you could try creating a clone when the item is selected and stamping it when it is in the cart so you can delete the clone. That helps avoid problems with clones responding to the when sprite clicked hat block as well as the sprite doing so. Alternatively give clones a cloneID of 1 while keeping the sprite as cloneID=0 so you can, again, only drag a newly created clone and only the sprite creates clones. If you do that it shouldn't be difficult to hide the sprite when the stock is 0 so it can't be dragged.
Hi thanks for replying! I have another question: Would the clone have the same commands as the original sprite or would it just be setting its cloneID to 1?…and the items in the cart do have to move with the cart…like each time I go to a different shelf, the clones (or the grey square boxes talked about below) should be viewed in the cart.
and how should I set up the CloneID? Because if I ‘set CloneID to 0’ for the original sprite, then it would just change to 1 when I clone it and it won't be 0 again…should I make 2 CloneID variables?
asivi
Scratcher
1000+ posts

Drag and Drop: Shopping Game

22ertyu wrote:

But, is it possible to work around the ‘stop’ blocks? and I want it so that when the user long presses the item it'll be draggable, but when they just click it once, this sprite will pop up which tells you info about the sprite. That's why I have:

when this sprite clicked
broadcast [software1 v]

so that the info sprite will show
Andddd when you stamp, is it possible to replace the stamped sprite with another new sprite which is a grey square that sits at the bottom, inside the cart?
I would use something like ‘if touching cart then broadcast….and clear’ The broadcast is for the grey box to show up right?

A remix for “software1” sprite https://scratch.mit.edu/projects/105696834/
deck26
Scratcher
1000+ posts

Drag and Drop: Shopping Game

22ertyu wrote:

22ertyu wrote:

deck26 wrote:

If the cart doesn't move with the objects inside you could try creating a clone when the item is selected and stamping it when it is in the cart so you can delete the clone. That helps avoid problems with clones responding to the when sprite clicked hat block as well as the sprite doing so. Alternatively give clones a cloneID of 1 while keeping the sprite as cloneID=0 so you can, again, only drag a newly created clone and only the sprite creates clones. If you do that it shouldn't be difficult to hide the sprite when the stock is 0 so it can't be dragged.
Hi thanks for replying! I have another question: Would the clone have the same commands as the original sprite or would it just be setting its cloneID to 1?…and the items in the cart do have to move with the cart…like each time I go to a different shelf, the clones (or the grey square boxes talked about below) should be viewed in the cart.
and how should I set up the CloneID? Because if I ‘set CloneID to 0’ for the original sprite, then it would just change to 1 when I clone it and it won't be 0 again…should I make 2 CloneID variables?
If the variable is ‘for this sprite only’ then each clone gets its own copy. So my thought was that the variable is set to 0 by the sprite and then at the start of the clone's script you set it to 1 and let the clone be dragged. So the sprite is not draggable but the clone is but only until the clone is placed - so ‘when this sprite clicked’ only allows clicking on the sprite, not the clone, because you check the cloneID.

However if you use stamping and delete the clone though you don't need the cloneID as the clone is only created when you click on the sprite and once you release the mouse the clone is no longer available to respond to the ‘when this sprite clicked’ script.
22ertyu
New to Scratch
28 posts

Drag and Drop: Shopping Game

asivi wrote:

22ertyu wrote:

But, is it possible to work around the ‘stop’ blocks? and I want it so that when the user long presses the item it'll be draggable, but when they just click it once, this sprite will pop up which tells you info about the sprite. That's why I have:

when this sprite clicked
broadcast [software1 v]

so that the info sprite will show
Andddd when you stamp, is it possible to replace the stamped sprite with another new sprite which is a grey square that sits at the bottom, inside the cart?
I would use something like ‘if touching cart then broadcast….and clear’ The broadcast is for the grey box to show up right?

A remix for “software1” sprite https://scratch.mit.edu/projects/105696834/
Thank you sooo much for the remix! Now I'm trying to make it so that each time the user goes to a different shelf that the grey blocks are still there…any idea how? I tried to hide and show when it switches to different backdrops but then it would mean that the original sprite (box) would show if the user didn't put it in their cart…I don't want it to show if the user didn't even pick up the item, only when they do. Thanks again
asivi
Scratcher
1000+ posts

Drag and Drop: Shopping Game

Create a list with the objects you has added to cart until the moment, then you can send a message to the sprites containnig the items in that list ordering to be stamped.
22ertyu
New to Scratch
28 posts

Drag and Drop: Shopping Game

asivi wrote:

Create a list with the objects you has added to cart until the moment, then you can send a message to the sprites containnig the items in that list ordering to be stamped.
So how would I make a sprite connected to an item in the list, and how would I stamp the item in the list? Would I have to make 3 items for software1 since it could go up to 3 of that item in the cart? Does this mean everytime it goes to a new shelf it would stamp the item? Yeah, I'm not really understanding the idea of lists…
furrypig
Scratcher
100+ posts

Drag and Drop: Shopping Game

asivi wrote:

Tested scripts, the sprite doesn't need to be draggable
when flag clicked
clear
hide
go to x:(30) y:(105)
set [Stock v] to [3]
hide variable [Stock v]


when backdrop switches to [SOFTWARE v]
clear
show
go to x:(43) y:(101)
show variable [Stock v]
forever
if <(Stock) = [0]> then
hide
stop [this script v]
end
end


when I receive [decrease Stock soft1 v]
change [Stock v] by (-1)


when this sprite clicked
create clone of [myself v]


when I start as a clone
go to front
show
repeat until <not <mouse down?>>
go to [mouse-pointer v]
end
if <<(x position) < [-40]> and <(y position) < [-30]>> then
broadcast [decrease Stock soft1 v]
go to x:(pick random (-120) to (-60)) y:(-90)
stamp
delete this clone
end
delete this clone


when backdrop switches to [storage & software v]
clear
hide
hide variable [Stock v]
stop [other scripts in sprite v]


when backdrop switches to [CHECK-OUT v]
clear
hide
hide variable [Stock v]
stop [other scripts in sprite v]
a problem in the scripts.
in the clone…
when I start as a clone
WAIT UNTIL <<mouse down?> and <<touching [mouse pointer v] ?> >>
the rest of the scripts as seen in asivi's clone script.
this way it waits until you grab it, (It used to not), then picks it up for dragging until you let go with the mouse, then tests if it's in the cart
asivi
Scratcher
1000+ posts

Drag and Drop: Shopping Game

furrypig wrote:

asivi wrote:

Tested scripts, the sprite doesn't need to be draggable
when flag clicked
clear
hide
go to x:(30) y:(105)
set [Stock v] to [3]
hide variable [Stock v]


when backdrop switches to [SOFTWARE v]
clear
show
go to x:(43) y:(101)
show variable [Stock v]
forever
if <(Stock) = [0]> then
hide
stop [this script v]
end
end


when I receive [decrease Stock soft1 v]
change [Stock v] by (-1)


when this sprite clicked
create clone of [myself v]


when I start as a clone
go to front
show
repeat until <not <mouse down?>>
go to [mouse-pointer v]
end
if <<(x position) < [-40]> and <(y position) < [-30]>> then
broadcast [decrease Stock soft1 v]
go to x:(pick random (-120) to (-60)) y:(-90)
stamp
delete this clone
end
delete this clone


when backdrop switches to [storage & software v]
clear
hide
hide variable [Stock v]
stop [other scripts in sprite v]


when backdrop switches to [CHECK-OUT v]
clear
hide
hide variable [Stock v]
stop [other scripts in sprite v]
a problem in the scripts.
in the clone…
when I start as a clone
WAIT UNTIL <<mouse down?> and <<touching [mouse pointer v] ?> >>
the rest of the scripts as seen in asivi's clone script.
this way it waits until you grab it, (It used to not), then picks it up for dragging until you let go with the mouse, then tests if it's in the cart

asivi wrote:

22ertyu wrote:

But, is it possible to work around the ‘stop’ blocks? and I want it so that when the user long presses the item it'll be draggable, but when they just click it once, this sprite will pop up which tells you info about the sprite. That's why I have:

when this sprite clicked
broadcast [software1 v]

so that the info sprite will show
Andddd when you stamp, is it possible to replace the stamped sprite with another new sprite which is a grey square that sits at the bottom, inside the cart?
I would use something like ‘if touching cart then broadcast….and clear’ The broadcast is for the grey box to show up right?

A remix for “software1” sprite https://scratch.mit.edu/projects/105696834/
22ertyu
New to Scratch
28 posts

Drag and Drop: Shopping Game

asivi wrote:

Create a list with the objects you has added to cart until the moment, then you can send a message to the sprites containnig the items in that list ordering to be stamped.
If I do that, it means I have to add an item to the list each time it is brought to the cart? For example, if the person drags 3 of the same item, then I need to make 3 items in the list, correct? And for the stamping, I tell the sprite to stamp if it contains the item in the list right? So it would move to a random spot, stamp, then move to another random spot, stamp, and then move to another spot, stamp and so on until there are three stamps or until each item is checked off, then it would hide, correct?
This means I need a variable in the original sprite to count each time it is brought to the cart and to add an item to the list each time right?
deck26
Scratcher
1000+ posts

Drag and Drop: Shopping Game

You presumably have a variable for each item to record the current stock level for that item so each time you buy one of those items you reduce that by 1. When it is 0 you hide the sprite.

Each new item gets added to the cart by stamping at the time you buy it so whether it's in a list at the point or not isn't important. The list may be useful later or may not be required.

So for example, your store has 5 bottles of milk. Player buys 1 so you create a clone and reduce the count to 4. The clone moves to the cart and stamps itself there and then deletes itself.
22ertyu
New to Scratch
28 posts

Drag and Drop: Shopping Game

deck26 wrote:

You presumably have a variable for each item to record the current stock level for that item so each time you buy one of those items you reduce that by 1. When it is 0 you hide the sprite.

Each new item gets added to the cart by stamping at the time you buy it so whether it's in a list at the point or not isn't important. The list may be useful later or may not be required.

So for example, your store has 5 bottles of milk. Player buys 1 so you create a clone and reduce the count to 4. The clone moves to the cart and stamps itself there and then deletes itself.
Yes this is true but I also want the items to show in the cart even when the player goes to a different shelf. For example, if I put one Adobe Photoshop CS6 item in my cart then I want to be able to see that box(in this case a grey box) inside the shopping cart when I go to the other shelves in the store, since it's not like each time I put something in the cart, I take the item out of the cart.
So I made a variable that counts how many of that item I have and each time it adds an item to the list and increases the cloneID by one. Then when it goes to another shelf, I put ‘if In Cart’(the list) contains ‘(1)Adobe Photoshop CS6’ then create clone.' Then under ‘when I start as a clone I put ’if cloneID=1 then go to a random place in the cart and stamp. If CloneID=2, then repeat this twice and if CloneID=3 repeat it 3 times and so on.' I have that code for this item in each shelf but it still doesn't work!!!!
22ertyu
New to Scratch
28 posts

Drag and Drop: Shopping Game

22ertyu wrote:

deck26 wrote:

You presumably have a variable for each item to record the current stock level for that item so each time you buy one of those items you reduce that by 1. When it is 0 you hide the sprite.

Each new item gets added to the cart by stamping at the time you buy it so whether it's in a list at the point or not isn't important. The list may be useful later or may not be required.

So for example, your store has 5 bottles of milk. Player buys 1 so you create a clone and reduce the count to 4. The clone moves to the cart and stamps itself there and then deletes itself.
Yes this is true but I also want the items to show in the cart even when the player goes to a different shelf. For example, if I put one Adobe Photoshop CS6 item in my cart then I want to be able to see that box(in this case a grey box) inside the shopping cart when I go to the other shelves in the store, since it's not like each time I put something in the cart, I take the item out of the cart.
So I made a variable that counts how many of that item I have and each time it adds an item to the list and increases the cloneID by one. Then when it goes to another shelf, I put ‘if In Cart’(the list) contains ‘(1)Adobe Photoshop CS6’ then create clone.' Then under ‘when I start as a clone I put ’if cloneID=1 then go to a random place in the cart and stamp. If CloneID=2, then repeat this twice and if CloneID=3 repeat it 3 times and so on.' I have that code for this item in each shelf but it still doesn't work!!!!
I was able to make the stamps show up since for some reason I put the ghost effect to 100. But each time I go to a different shelf, the Adobe Photoshop CS6 box shows up on the shelf even when the player isn't in the ‘software’ shelf. It's like a clone since when I dragged it, it disappeared. And whenever I go to a new shelf the grey boxes multiply a lot, but I think that can be soled by clearing each time?

Powered by DjangoBB