# What’s wrong with my code?

So I’ve checked everything and I have no idea why it’s not working. The squares are supposed to stack on top of each other as you can see in the photo right above this one. So I’ve got that one down and yes I know it’s overlapping a bit but I know how to fix that.
The problem is squares which ‘ appear ’ at the ends of the platform from x coordinates 35 to 121 and 909 to width - 35 fall down and go further than they’re supposed to ( only meant to change in y by -550 ) as shown in the block Land Wave. So they go further than they’re supposed to for some reason and they reach the bottom of the screen, they then stop and don’t create another clone so the whole thing stops but as long as it doesn’t create a clone at the x coordinates near the two ends of the platform then it works perfectly ( pretty much ) and stacks.

4 Likes

Yeh… It’s actually not the photo right above and in fact the very first photo. Sorry for any confusion.

4 Likes

Couldn’t you just make the squares not appear at the sides then?
Idk I think that would be the easiest solution but maybe others like @ThinBuffalo or @Petrichor could help you.

2 Likes

I guess but I’d prefer not to.

1 Like

Hi I’m a pro at this tell me your difficulty in detail

1 Like

Tell me your difficulty in detail I’ll see if I know I’m pro at this idk if u seen it but I made Crossy road on hop scotch?

1 Like

The problem is in the 2 rules shown in picture 3 and 5
When x position… and When object is cloned
When game starts object will be cloned so we know that’s working
The object cloned will go to a random x position and then fall by -8 until self land = either 1,2 or 3
if x position is either < 121 or > 909 and y < 150 then the rule in picture 3 will set self land to 3
The fall block contains a block that checks if land = 1,2 or 3 if it is 3 then the block land wave should make the clone stop falling increase self land by -3, become invisible and clone itself as shown in picture 7
This will repeat the process above going to a random x position, falling and so on.
So the problem is here
‘ should make the clone stop falling increase self land by -3, become invisible and clone itself. ’
The clone just keeps moving despite self land being 3 and doesn’t become invisible or make a clone which stops the loop.
Hope this clarifies everything.

2 Likes

This seems complicated… but I’m sure that it isn’t when you figure it out!
Could you possible publish your project and then tap the “Share” icon next to it? If you then tap “Copy link” and unpublish project again, you will create a shareable link that only people that has access to it can use to see your project. It will not show up in your “Published” tab.

If you don’t want to do that, ask ThinBuffalo, somebody who is really helpful and knows a lot about these kinds of issues.

2 Likes

https://c.gethopscotch.com/p/zm7rvem91
I’ve got another problem along with the still unsolved one above

In this photo, you see more squares than in the previous photo because as explained if squares set at a x position of < 121 or > 909 then problem 1 will occur causing the square to continue to fall despite the when rule setting self ( land ) to 3 and which should cause the square to stop, increase self ( land ) by -3, become invisible and create a clone however it doesn’t stopping the loop. In this photo however no squares have been set at the specified position which meant more squares continued to be cloned.
Now to explain problem 2.
The clone blocks are in repeat forever loops however total objects are less than 30 never mind 4000 yet the game starts to lag after around 5 squares have been cloned.
The squares then start to land mid air and stay there and create other clones that do the same landing mid air instead of landing on the platform or on other blocks
These squares gradually land mid air higher and higher until it reaches 700 where it appears and the squares just start appearing right next to each other not falling at all.
Two major problems. Any help is appreciated.

1 Like

I replied earlier but accidentally deleted the post xD

1 Like

For problem 1
I realised if the object is falling by -550 the squares final y wouldn’t be below 150 as it starts at 700 so I’ve changed the rule to be < 220 and not 150

However this did not fix it neither did I expect it to as the rule used to not have the y position anyways.

Oh and by the way I’m calling the problem with the squares appearing at the sides problem 1 and problem 2 is the one with the squares staying in mid air.

This could be caused by using collision when blocks.
Here is a better way

It could also be caused by all the repeat forever blocks which you could have not used.
Any repeat forevers in the fall ability could be avoided.

Try using the above method of detecting collisions in place of the fall variable. And eliminating the repeat forever blocks without changing how it works. I’ll do it now as an example, let me know if you need anymore help.

1 Like

Hmmm.

Okay, because of Hopscotch having broken collision boxes when there are clones (problem 2’s cause I think) and any reference to Object variables that aren’t self refer to the original object, I can’t find a way for it to be stopped by other squares.

2 Likes

As I understand it you’re saying that with the method you mentioned above by @ThinBuffalo I could avoid the repeat forevers but as a result another problem is created which causes the squares to overlap each other and not stack when clones collide into each other and not the original object.
But I don’t really understand that because couldnt you just use a
{ When self bumps anything } block?
Is problem 2 ( the squares staying mid air ) caused by lag ( caused by the repeat forever blocks ) or by the code and variables being messed up?

1 Like

Won’t be on for a while so any help in the mean time is appreciated. ‍♂️

1 Like

This may be what causes problem two.

When there are too many clones close together the Object has a larger than usual collision box.
https://forum.gethopscotch.com/t/bug-with-bumping-several-clones-at-once/39820?u=nindroidgames

This may have been fixed by now, but I don’t think it was.

1 Like

Hi @Revilo

If x position is either < 121 or > 909 and y < 150 then

The formula in the project doesn’t match this

The project has:
If x position < 121 and x position > 909
which are mutually exclusive so land = 3 never gets set.

1 Like

Thanks @ThinBuffalo
Problem 1 has been solved and it was quite easy just that 1 simple overlook.
However problem 2 seems more complicated. @Petrichor I’ve read the two posts and understand it a bit more now ( I think )
So I also think the bug still hasn’t been fixed and the solution may be in the method you described

Distance is sqrt(deltaX^2 + deltaY^2)
Then distance should be replaced with sqrt( 136^2 + 69^2 )
Right?
Since each square is 68 pixels and if a square lands on another’s corner then the change in x between them would be 68 x 2 ?
And 69 is 1 pixel above 68 so that’s for it landing on top?
Don’t really understand this