Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » Help please. These two scripts are lagging my game 1000%
- SleepiiFox
-
Scratcher
14 posts
Help please. These two scripts are lagging my game 1000%
image I'm working on a huge project and I've just finished my first enemy AI.
While making this project, I've had tons of scripts that made the game run super slow but I managed to fix them all on my own.
With these two Scripts, I'm totally puzzled. They make the game have about one frame per 5 seconds.
Here is a link to screenshot because complications
I know it's these scripts because if I remove them both, the entire project runs so fast that I'm amazed. If I remove just one or the other then the game becomes unplayable. All of the custom blocks run without screen refresh. I've tried changing the wait blocks in the loops to much larger numbers but it doesn't help any.
After a little more testing, the problem seems to be the two identical booleans that are really long.
It's odd because that part of the script on the left slows everything down when the first loop (until not touching edge) isn't even done.
I don't know how to work around these
While making this project, I've had tons of scripts that made the game run super slow but I managed to fix them all on my own.
With these two Scripts, I'm totally puzzled. They make the game have about one frame per 5 seconds.
Here is a link to screenshot because complications
I know it's these scripts because if I remove them both, the entire project runs so fast that I'm amazed. If I remove just one or the other then the game becomes unplayable. All of the custom blocks run without screen refresh. I've tried changing the wait blocks in the loops to much larger numbers but it doesn't help any.
After a little more testing, the problem seems to be the two identical booleans that are really long.
It's odd because that part of the script on the left slows everything down when the first loop (until not touching edge) isn't even done.
I don't know how to work around these
- RokCoder
-
Scratcher
1000+ posts
Help please. These two scripts are lagging my game 1000%
You can't use wait commands inside custom blocks that are running without screen refresh
- Th3DiamondMin3craft
-
Scratcher
100+ posts
Help please. These two scripts are lagging my game 1000%
image I'm working on a huge project and I've just finished my first enemy AI.
While making this project, I've had tons of scripts that made the game run super slow but I managed to fix them all on my own.
With these two Scripts, I'm totally puzzled. They make the game have about one frame per 5 seconds.
Here is a link to screenshot because complications
I know it's these scripts because if I remove them both, the entire project runs so fast that I'm amazed. If I remove just one or the other then the game becomes unplayable. All of the custom blocks run without screen refresh. I've tried changing the wait blocks in the loops to much larger numbers but it doesn't help any.
After a little more testing, the problem seems to be the two identical booleans that are really long.
It's odd because that part of the script on the left slows everything down when the first loop (until not touching edge) isn't even done.
I don't know how to work around these
I think it's the wait commands.
- SleepiiFox
-
Scratcher
14 posts
Help please. These two scripts are lagging my game 1000%
You can't use wait commands inside custom blocks that are running without screen refresh
I think it's the wait commands.
Thank you, merely turning off run without screen refresh fixed the problem. I had no idea it ruins projects to use wait blocks in them.
Maybe it's because when they have to wait, every other wait block in the project has to wait for it to run?
- RokCoder
-
Scratcher
1000+ posts
Help please. These two scripts are lagging my game 1000%
I had no idea it ruins projects to use wait blocks in them.
Maybe it's because when they have to wait, every other wait block in the project has to wait for it to run?
To be fair, it's not just the wait command - it's also that you're running forever loops in those non-refresh blocks.
Normally (with screen refresh enabled) operations such as loops will cause program flow to yield to other blocks and processes that are active. If you're running a forever loop inside a non-refresh block, it won't yield at all to other blocks and processes until the pre-defined system timeout hits. This means that other processes are only run once every 500ms (if I remember correctly).
You're going to run into problems with wait or broadcast and wait commands as well. Internally, the timer isn't updated during a non-refresh block. This means that when you perform a wait, it's going to wait forever for the timer to reach the target value (and will time out after 500ms). A broadcast and wait isn't going to work as intended because other processes don't run during a non-refresh block so it's going to get stuck waiting for an external process to complete (and, again, is going to time out at 500ms).
- best-games-ever
-
Scratcher
500+ posts
Help please. These two scripts are lagging my game 1000%
Yes, for me it works better without forever loops unless i really want something forever. I would not want it to wait forever.
- Discussion Forums
- » Help with Scripts
-
» Help please. These two scripts are lagging my game 1000%