Discuss Scratch

Cub56
Scratcher
1000+ posts

Racing Game Bug

In this game:

Click here

You are supposed to win a race if you complete 2 laps faster than your opponent.

When you first start the game, if you lose your first race, when you play your next race you will win the race after completing ONE lap, not 2. (But if you win your first race, this doesn't happen.)

This seems to happen whenever you lose a race regardless of whether it's your first race or not.

Why is there this lap bug and how do I fix it? Thanks very much and I will credit.

Last edited by Cub56 (March 17, 2017 10:52:58)


Check out Life Raft Survival, my new advanced sandbox survival game with crafting, building, transportation, weather events, tropical storms, and more!

In the game you're stranded at sea after a mysterious crash and must survive in an unforgiving tropical island environment collecting resources and crafting, in an attempt to finally be rescued.



deck26
Scratcher
1000+ posts

Racing Game Bug

Try to avoid repeating scripts - the Countdown sprite doesn't need 4 identical scripts. Either have a broadcast in that sprite so it responds to the 4 types by broadcasting to the single script or make a single script and change where you select the track type.

The different track types could probably be costumes of one sprite to further simplify and reduce repetition.

Make changes like that and your 102 scripts can probably be reduced by at least 60% which will make it easier to follow your code.

The most likely cause of your problem is you're not resetting the lap count variable at the start of the second race.
Cub56
Scratcher
1000+ posts

Racing Game Bug

deck26 wrote:

Try to avoid repeating scripts - the Countdown sprite doesn't need 4 identical scripts. Either have a broadcast in that sprite so it responds to the 4 types by broadcasting to the single script or make a single script and change where you select the track type.

The different track types could probably be costumes of one sprite to further simplify and reduce repetition.

Make changes like that and your 102 scripts can probably be reduced by at least 60% which will make it easier to follow your code.

The most likely cause of your problem is you're not resetting the lap count variable at the start of the second race.
The scripts can be reduced, but the lap count is being reset at the start of every race, as in the finish line sprite scripts.

Check out Life Raft Survival, my new advanced sandbox survival game with crafting, building, transportation, weather events, tropical storms, and more!

In the game you're stranded at sea after a mysterious crash and must survive in an unforgiving tropical island environment collecting resources and crafting, in an attempt to finally be rescued.



deck26
Scratcher
1000+ posts

Racing Game Bug

Well perhaps it has something to do with a forever loop still running from the previous race. If you race over 1 circuit the car starts a forever loop but then starts another when you start another circuit. Do you get the problem if you race again on the same circuit?

Still think simplifying should be the first priority.
Cub56
Scratcher
1000+ posts

Racing Game Bug

I think I've fixed the bug now with a “stop other scripts in sprite” at the end of a race. Would you like me to credit you?

Check out Life Raft Survival, my new advanced sandbox survival game with crafting, building, transportation, weather events, tropical storms, and more!

In the game you're stranded at sea after a mysterious crash and must survive in an unforgiving tropical island environment collecting resources and crafting, in an attempt to finally be rescued.



deck26
Scratcher
1000+ posts

Racing Game Bug

Cub56 wrote:

I think I've fixed the bug now with a “stop other scripts in sprite” at the end of a race. Would you like me to credit you?
No need to do so. Glad you've got it fixed but do watch for repeated code - it can almost always be avoided and makes later changes/debugging easier.

Last edited by deck26 (March 17, 2017 19:23:19)

0638815
New to Scratch
1 post

Racing Game Bug

yo guys whenever i press the arrow keys It teleports the car and gets stuck
Nezon
Scratcher
1000+ posts

Racing Game Bug

0638815 wrote:

yo guys whenever i press the arrow keys It teleports the car and gets stuck
Please don't necropost. This topic is old! You should create your own and get people to help you (include a project link)

This is my signature (it goes automatically under every post I make)! Here is a bit of advice on foruming, by the way. Don't do SAND. SAND means four words.
SAND means Spam, Advertising, Necroposting, and Derailing.
Spam is when a irrelevant message is sent to many places. Wiki Article: Spam
Advertising is when you promote your studios and projects. Wiki Article: Advertising
Necroposting is when you post on a old topic. It distracts other helpers! Wiki Article: Necroposting
Derailing is when you post something that is irrelevant to the topic, like minimodding. It is called thread hijacking. Wiki Article: Derailing(Derailing idea comes from this guy),
in the process of leaving scratch.
bob has been hidden again :(

Powered by DjangoBB