Discuss Scratch

samaneh_62
New Scratcher
39 posts

drag and drop

Hi
I'm new in Scratch and happy to be here
How we can drag a sprite on another sprite and then increase a counter?
Actually I want to make this game:
http://www.topmarks.co.uk/learning-to-count/gingerbread-man-game
part Counting
can any one help please?
Tnx
BKFighter
Scratcher
1000+ posts

drag and drop

You can make a sprite draggable as an option of the sprite. Click on the blue arrow in top right corner of the sprite on the bottom of the editor.

when green flag clicked
forever
if <touching [sprite v] ?> then
change [counter v] by (1)
stop [this script v]
end
end
Put in each sprite.
samaneh_62
New Scratcher
39 posts

drag and drop

Hi again
Now I succeeded to make great part of this project.I have this :
this
want to put 5 button on dress
but I don't know which event should I use.I tried both two “when flag clicked” and “when this sprite clicked” events but didn't get acceptable result.
any idea plz?

Last edited by samaneh_62 (Dec. 6, 2015 22:41:06)

BKFighter
Scratcher
1000+ posts

drag and drop

1) Try
<<[] < [ ]> and <[] > [ ]>>//See less than one but greater than one, you used to less than
2) Those scripts need to be in a forever loop, and probably under this sprite clicked.
samaneh_62
New Scratcher
39 posts

drag and drop

Hi again
Now I succeeded to make great part of this project.I have this :

http://s1.upload7.ir/uploads/YQuoBsF4.png/Untitlesd.png

want to put 5 button on dress
but I don't know which event should I use.I tried both two “when flag clicked” and “when this sprite clicked” events but didn't get acceptable result.
any idea plz?
BKFighter
Scratcher
1000+ posts

drag and drop

As I said you need to use:
when this sprite clicked
forever
// Insert the scripts you have here
end
samaneh_62
New Scratcher
39 posts

drag and drop

But if I use “forever”,my count variable will Increase forever.I want it change 1 unit.
BKFighter
Scratcher
1000+ posts

drag and drop

samaneh_62 wrote:

But if I use “forever”,my count variable will Increase forever.I want it change 1 unit.
That's why you put:
stop [this script only v]
Like I originally said.
samaneh_62
New Scratcher
39 posts

drag and drop

Thank you so much.it worked
next prob ,I want to this code active when I drag a button and drop it on shirt,exactly now increase 1 unit not by clicking or clicking flag.
Is there any solution?
Tnx again
BKFighter
Scratcher
1000+ posts

drag and drop

You could use any of the event blocks, but make sure the sprites keep track of their position, not the mouses position, so use these:
(x position)
(y position)
not these
(mouse x)
(mouse y)

Last edited by BKFighter (Dec. 7, 2015 00:07:34)

samaneh_62
New Scratcher
39 posts

drag and drop

I worked at it so much but couldn't solve
can I suggest you write the code of one button in this game(bottom link) please ?

http://www.topmarks.co.uk/learning-to-count/gingerbread-man-game

in counting part
deck26
Scratcher
1000+ posts

drag and drop

samaneh_62 wrote:

I worked at it so much but couldn't solve
can I suggest you write the code of one button in this game(bottom link) please ?

http://www.topmarks.co.uk/learning-to-count/gingerbread-man-game

in counting part
Ignore the ‘make sprite draggable in player’ option - it is better avoided in most projects.

when this sprite clicked
repeat until <not <mouse down?>>

go to [mouse pointer v]
end
if <touching [gingerbreadman v] ?> then

change [count v] by (1)
else
go to x: () y: () // put it back where it was
end
samaneh_62
New Scratcher
39 posts

drag and drop

True but still doesn't increase count when we drop button.
deck26
Scratcher
1000+ posts

drag and drop

samaneh_62 wrote:

True but still doesn't increase count when we drop button.
If you're responding to my post it will increase count by 1 when the button is released on the gingerbreadman.

Ideally the button needs then not to be moveable until that round of the game is completed to avoid someone dragging it off and on again.

Last edited by deck26 (Dec. 7, 2015 12:48:42)

deck26
Scratcher
1000+ posts

drag and drop

https://scratch.mit.edu/projects/90437876/#player was for someone else asking about drag and drop but I've added a counter.
samaneh_62
New Scratcher
39 posts

drag and drop

deck26 wrote:

samaneh_62 wrote:

True but still doesn't increase count when we drop button.
If you're responding to my post it will increase count by 1 when the button is released on the gingerbreadman.

Ideally the button needs then not to be moveable until that round of the game is completed to avoid someone dragging it off and on again.


I used your code again but it work by clicking not releasing.

“Ideally the button needs then not to be movable until that round of the game is completed to avoid someone dragging it off and on again”
Actually you guess my another problem truly . what we can do for solving this?can we lock a sprite?
deck26
Scratcher
1000+ posts

drag and drop

samaneh_62 wrote:

deck26 wrote:

samaneh_62 wrote:

True but still doesn't increase count when we drop button.
If you're responding to my post it will increase count by 1 when the button is released on the gingerbreadman.

Ideally the button needs then not to be moveable until that round of the game is completed to avoid someone dragging it off and on again.


I used your code again but it work by clicking not releasing.

“Ideally the button needs then not to be movable until that round of the game is completed to avoid someone dragging it off and on again”
Actually you guess my another problem truly . what we can do for solving this?can we lock a sprite?
It should only increase count when released by the mouse. Are you sure you've switched off the draggable option? I'd need to see your project to help further if you're saying it works differently to what I expect.

To avoid double counting you could do several things.

1 - only allow the button to be placed once per round. So at the start of each round a (for this sprite only) ‘placed’ variable is set to 0 and you set it to 1 when the button is placed on the gingerbreadman. You only allow the button to be moved when ‘placed’ = 0.

2 - allow the buttons to be moved off the gingerbreadman if desired by the player. So when you click on the sprite you subtract 1 from count if it is currently touching the gingerbreadman. That way if it ends up touching him again you add 1 and count is still the same but if not touching you've reduced count as required.

Option 2 is probably easiest and allows the player to move the buttons after placement if they wish to do so.

A near alternative to 2 is to set a variable to -1 when the button is clicked and touching or 0 if not touching. Then when the button is released and touching you change count by 1 + the new variable and if not touching you change count by the new variable. That is neater if count is displayed as it means count is only ever changed when the button is released.

Last edited by deck26 (Dec. 7, 2015 13:11:21)

samaneh_62
New Scratcher
39 posts

drag and drop

oooohh it worked by releasing.yes sorry,I had not switched off the draggable option.Thanks,I love you
so for now I should work on next stage that you describe completely.Thank you so much
samaneh_62
New Scratcher
39 posts

drag and drop

I couldn't solve it.can you write code of second solution?
samaneh_62
New Scratcher
39 posts

drag and drop

I wrote this:
when this sprite clicked
if <<touching [ v] ?> and <<mouse down?> >> then

change [ v] by (-1)
end

it seems that it works.is it true?

Powered by DjangoBB