Discuss Scratch

DensetsuNo
New Scratcher
12 posts

Help Debugging Project

Hey Guys,
for some reason my project (star shooter) started going crazy after some apparently harmless additions.

Link to the project: Star Shooter

Problems:
1) Stars Movement.
The very movement of the stars is now erratic, it worked perfectly (and still does in an old copy of the project) but now is going gaga.

This is the line of “code” I implemented:
http://i.imgur.com/DbljkAV.png

And is implemented in two sprites: Star and Star Game, both of which stopped working (although in two different ways, which puzzles me further )

2) End of the game.
Basically my project is a shooter in which you have to shoot at a star to score points, after you hit a star a clone will appear and after a few seconds it will disappear. The game end either when you reach the 60seconds time limit. Or when all stars have disappeared. The first game mode was easily implemented with a timer, while I am finding a lot of trouble implementing the second one.

This is the solution I implemented:
http://i.imgur.com/gNABTfx.png

And again I don't see why it shouldn't work.

I will have to rely on you guys, every change I am making atm seems just to make matters worse.
footsocktoe
Scratcher
1000+ posts

Help Debugging Project

In this one … http://i.imgur.com/DbljkAV.pngI think you don't want a “turn” block, you want a “direction” block.

Turn would not do anything since you have left/right for a rotation style.


I don't know what I was thinking there…

Last edited by footsocktoe (March 13, 2017 14:05:38)

deck26
Scratcher
1000+ posts

Help Debugging Project

footsocktoe wrote:

In this one … http://i.imgur.com/DbljkAV.png … I think you don't want a “turn” block, you want a “direction” block.

Turn would not do anything since you have left/right for a rotation style.
Turn will still change direction even though the sprite doesn't rotate so it shouldn't matter unless I'm missing something.
TheLogFather
Scratcher
1000+ posts

Help Debugging Project

You need to centre your star costumes.

When you rotate a costume, it rotates about the point at the centre of the costume screen. Similarly, when you have rotation style left-right, it will flip around the centre point.

At the moment you have the stars *way* off that centre, so turning a star costume will make it appear to be in a completely different place, as it ‘flips’ between left and right directions depending on the sign of the current ‘direction’.

(BTW, why do you have it set to rotation style left-right?)

Last edited by TheLogFather (March 13, 2017 08:48:37)

DensetsuNo
New Scratcher
12 posts

Help Debugging Project

TheLogFather wrote:

You need to centre your star costumes.

When you rotate a costume, it rotates about the point at the centre of the costume screen. Similarly, when you have rotation style left-right, it will flip around the centre point.

At the moment you have the stars *way* off that centre, so turning a star costume will make it appear to be in a completely different place, as it ‘flips’ between left and right directions depending on the sign of the current ‘direction’.

(BTW, why do you have it set to rotation style left-right?)


Thanks, it worked!! I still wonder why it didn't act like that from the beginning, anyway it's a relief to see that things sorted themselves out!

Do you have any suggestion on the second point?

I am looking for a reliable way to do two things:
1. count the number of sprites currently active
2. make sure that after a random # of seconds clones do actually disappear (for some reasons some don't, and this messes up the count)
TheLogFather
Scratcher
1000+ posts

Help Debugging Project

DensetsuNo wrote:

Thanks, it worked!! I still wonder why it didn't act like that from the beginning…
Presumably because you were not changing the direction of the stars, so the costumes didn't ‘flip’…?


DensetsuNo wrote:

Do you have any suggestion on the second point?
Do you know how to make a clone do something?

The script you gave there has the “delete this clone” in the same script as the script that has the “create clone” block. –But it's not the clone that's running that script, so that “delete” block isn't deleting the newly created clone. (It's trying to delete the sprite that was clicked – which will not work if that's the original sprite, since that's not a clone.)

To make a clone do something, you have to use the “when I start as a clone” hat block.

I'd suggest something like this:
whenIstartasaclonechangecloneCountby1dostuffwiththisclone...changecloneCountby-1deletethisclone

One important thing to note about clones (a common trap that many fall into)…

Clones receive broadcasts, and run receiver scripts just like the original sprite.
That means, if you want the clone to do something different from the original sprite when it receives the broadcast (or to do nothing at all, ‘cos you only want the original sprite to respond), then you need some way to distinguish between the clone(s) vs original sprite in that script. Suggestions might be the costume number (maybe the clone has a different costume to the original sprite), or a local variable (i.e. “this sprite only”) that gets set to a different value in the “when I start as a clone” block.

This is particularly important if you have a receiver script which creates a clone(s), since if the clones also receive it then it may well mean that all each and every one of your clones is also creating yet another clone of itself… leading to exponential clone explosion…

Also, note that’s true of all such event hat blocks, such as “when key pressed”, “when this sprite clicked”, etc. – clones also run those scripts.
You have a “when clicked” script which creates a clone. But that means you can click the clone, and it will then respond in just the same way as the original sprite (by running that script and creating a clone).


Yeah… clones can be tricky when you first start playing around with them – but they're dead useful once you get the hang of them…

Hope that helps!

Last edited by TheLogFather (March 13, 2017 13:29:41)

footsocktoe
Scratcher
1000+ posts

Help Debugging Project

deck26 wrote:

footsocktoe wrote:

In this one … http://i.imgur.com/DbljkAV.png … I think you don't want a “turn” block, you want a “direction” block.

Turn would not do anything since you have left/right for a rotation style.
Turn will still change direction even though the sprite doesn't rotate so it shouldn't matter unless I'm missing something.

Yeah. I don't know what I was thinking. I guess when you send a sprite spinning off at an angle. You use direction for the angle and turn to make it spin.
TheLogFather
Scratcher
1000+ posts

Help Debugging Project

OK, I finally got around to actually trying out the project… ()
…and I see that much of what I wrote above doesn't seem immediately relevant… (^2)

In particular, what I wrote about using “when I start as a clone” isn't really relevant, ‘cos you do want the clicked clone to disappear and get deleted after some time.

Also, your clone counting should work fine once you take into account the following point…

I think the most relevant thing relating to what I wrote above is that “when backdrop switches” hat block scripts are also run by clones (just as I mentioned about the other hat blocks).

I think you should be careful to ensure that you delete all star clones that are no longer needed (e.g. at the end of a game, or when new game starts) – i.e. not just hiding them – otherwise they will all be running those scripts concurrently, and probably ’interfering' in various ways.


Still, I don't see how you can have “the game end… …when all stars have disappeared”, since that can't possibly happen, can it?

I mean, a star only disappears a few seconds after you've clicked it. But when you click a star it creates a new one. So how can all stars disappear…?
(Maybe, you intend to have a star disappear after some more time even without clicking it…?)


Anyway, hope my rambling makes a bit more sense for this project than my previous post!

Last edited by TheLogFather (March 13, 2017 14:44:03)

DensetsuNo
New Scratcher
12 posts

Help Debugging Project

TheLogFather wrote:

OK, I finally got around to actually trying out the project… ()
I think you should be careful to ensure that you delete all star clones that are no longer needed (e.g. at the end of a game, or when new game starts) – i.e. not just hiding them – otherwise they will all be running those scripts concurrently, and probably ‘interfering’ in various ways.
Basically what I did here was a 3 step process:
1st: http://i.imgur.com/2e6JpwL.png
Say “when backdrop changes switch to the star costume, set Sprite count to 1, and start bouncing around”

2nd: http://i.imgur.com/ZofDowu.png
Whenever the sprite is clicked add 100points to the score, increase speed by 0.125, and create a clone. This clone follows the rules of (http://i.imgur.com/3tOcGOx.png) this script, that basically are the same as the original star + some color tricks. Then after the clone is created the Sprite Count increases by 1. AND HERE'S THE TRICK I thought about. Every time a clone is created I set a random countdown after which there is a “Change Sprite Count by -1” and a “Delete this clone”.

3rd: http://i.imgur.com/PU5Ohq6.png
It should then finish with something like. When Sprite count = 0, end game.

TheLogFather wrote:

OK, I finally got around to actually trying out the project… ()
Still, I don't see how you can have “the game end… …when all stars have disappeared”, since that can't possibly happen, can it?

I mean, a star only disappears a few seconds after you've clicked it. But when you click a star it creates a new one. So how can all stars disappear…?
(Maybe, you intend to have a star disappear after some more time even without clicking it…?)

Yeah, the timer I was talking about above should make all stars disappear after a random amount of time (1-5 seconds). At the beginning the Sprite Count and Clone elimination worked really well, but after 10-20 seconds they started forgetting about clones (i.e. not eliminating them) and the Sprite Count went gaga. And that's where I am confused.

TheLogFather wrote:

Anyway, hope my rambling makes a bit more sense for this project than my previous post!

Yes, absolutely, thanks mate. Let's see if you figure out what's wrong again.
Nightseeker600
Scratcher
41 posts

Help Debugging Project

I tried it, and it's not very bad to me.
DensetsuNo
New Scratcher
12 posts

Help Debugging Project

Nightseeker600 wrote:

I tried it, and it's not very bad to me.
Thanks man, nice to hear it. Still, having a Sprite count that works would allow more freedom in controlling the game mechanics (eg. less stars wondering around) making it more fun! :-)
DensetsuNo
New Scratcher
12 posts

Help Debugging Project

up

Powered by DjangoBB