This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2010-08-30 20:26:09

Sunrise-Moon
Scratcher
Registered: 2009-06-27
Posts: 1000+

Tutorial: How to Eradicate Lag in Your Game

Lag making your game unplayable? Here are a few tips to help eradicate the lag and keep your gameplay smooth as a smoothie:

1. Show as few variables and lists as possible - Variables and lists slow down movement in your game. When playtesting your game, make sure to hide all unnecessary variables.

2. Use as few sprites as possible - I find that many sprites usually slow down projects to a crawl. If you NEED some stuff to be shown, try putting it in the background, or using one sprite with different costumes and scripts.

3. Try to use less scripts/combine as many scripts as possible into one script - The more scripts running at any time, the slower your game will be. If you combine a bunch of scripts into one big script, your game will be a lot smoother. Obviously, you can't do this with all scripts because of stuff like 'Wait Until <______>'.

4. Use as few loops (forevers, repeats) and "When green flag clicked" as possible - This tip goes hand-in-hand with the last tip. Loops and "When green flag clicked's" are the root of most of your lag. If you can combine your other scripts into one script, there won't be a need for very many loops and "When green flag clicked's".

If you have any more tips, post and I'll try and add them  big_smile

Last edited by Sunrise-Moon (2010-08-30 21:21:09)


http://i1067.photobucket.com/albums/u427/HulKDzN/RebornBlade.png

Offline

 

#2 2010-08-30 20:31:52

coolstuff
Community Moderator
Registered: 2008-03-06
Posts: 1000+

Re: Tutorial: How to Eradicate Lag in Your Game

Excellent guide! My one suggestion is to put more emphasis on the last point, as it is the primary reason for almost all lag. Replacing them with "repeats" is obviously the way to go; most forever blocks are only needed at one or two points during the game

Other than that, fantastic guide!

Offline

 

#3 2010-08-30 20:33:18

Jwosty
Scratcher
Registered: 2009-12-19
Posts: 500+

Re: Tutorial: How to Eradicate Lag in Your Game

Wow! Great tutorial! Maybe a little more info (if any is found) and it would be a perfect sticky-worthy topic! Keep up the good work.  smile


http://i39.tinypic.com/18ert5.png Google it.  smile

Offline

 

#4 2010-08-30 20:39:20

Sunrise-Moon
Scratcher
Registered: 2009-06-27
Posts: 1000+

Re: Tutorial: How to Eradicate Lag in Your Game

coolstuff wrote:

Excellent guide! My one suggestion is to put more emphasis on the last point, as it is the primary reason for almost all lag. Replacing them with "repeats" is obviously the way to go; most forever blocks are only needed at one or two points during the game

Other than that, fantastic guide!

Thanks! I added another little sentence saying that they're the root of most of the lag.

Jwosty wrote:

Wow! Great tutorial! Maybe a little more info (if any is found) and it would be a perfect sticky-worthy topic! Keep up the good work.  smile

Thank you! This is basically all I know about lag right now, but maybe other people know some other stuff about the lag.

Last edited by Sunrise-Moon (2010-08-30 20:40:57)


http://i1067.photobucket.com/albums/u427/HulKDzN/RebornBlade.png

Offline

 

#5 2010-08-30 20:44:32

Jwosty
Scratcher
Registered: 2009-12-19
Posts: 500+

Re: Tutorial: How to Eradicate Lag in Your Game

Sunrise-Moon wrote:

Jwosty wrote:

Wow! Great tutorial! Maybe a little more info (if any is found) and it would be a perfect sticky-worthy topic! Keep up the good work.  smile

Thank you! This is basically all I know about lag right now, but maybe other people know some other stuff about the lag.

Yea, I go a weird color sensing glitch on this project, but it's probbably because of the online Java Player...  tongue

Last edited by Jwosty (2010-08-30 20:44:44)


http://i39.tinypic.com/18ert5.png Google it.  smile

Offline

 

#6 2010-08-30 20:52:04

Sunrise-Moon
Scratcher
Registered: 2009-06-27
Posts: 1000+

Re: Tutorial: How to Eradicate Lag in Your Game

Jwosty wrote:

Sunrise-Moon wrote:

Jwosty wrote:

Wow! Great tutorial! Maybe a little more info (if any is found) and it would be a perfect sticky-worthy topic! Keep up the good work.  smile

Thank you! This is basically all I know about lag right now, but maybe other people know some other stuff about the lag.

Yea, I go a weird color sensing glitch on this project, but it's probbably because of the online Java Player...  tongue

Yeah, the project seems to run at a pretty good speed, so I don't think it has anything to do with lag in the project.


http://i1067.photobucket.com/albums/u427/HulKDzN/RebornBlade.png

Offline

 

#7 2010-08-30 20:55:32

Jwosty
Scratcher
Registered: 2009-12-19
Posts: 500+

Re: Tutorial: How to Eradicate Lag in Your Game

Sunrise-Moon wrote:

Jwosty wrote:

Sunrise-Moon wrote:

Thank you! This is basically all I know about lag right now, but maybe other people know some other stuff about the lag.

Yea, I go a weird color sensing glitch on this project, but it's probbably because of the online Java Player...  tongue

Yeah, the project seems to run at a pretty good speed, so I don't think it has anything to do with lag in the project.

Oops!  yikes  It isn't a lag problem, the bugs just spin in circles when they get to the edges. But Paddle had a suggestion that worked to fix that!  big_smile

I made the pen marks thicker and the sensors on the bugs bigger, and now I have ERADICATED the problem.  big_smile


http://i39.tinypic.com/18ert5.png Google it.  smile

Offline

 

#8 2010-08-30 21:17:07

Jonathanpb
Scratcher
Registered: 2008-07-25
Posts: 1000+

Re: Tutorial: How to Eradicate Lag in Your Game

Excellent guide! You might want to mention the dangers of loops though.  smile


"Human beings... must have action; and they will make it if they cannot find it.
-Charlotte Brontë

Offline

 

#9 2010-08-30 21:20:26

Sunrise-Moon
Scratcher
Registered: 2009-06-27
Posts: 1000+

Re: Tutorial: How to Eradicate Lag in Your Game

Jonathanpb wrote:

Excellent guide! You might want to mention the dangers of loops though. :)

Thanks! Alright, I'll add it in with the last tip :o


http://i1067.photobucket.com/albums/u427/HulKDzN/RebornBlade.png

Offline

 

#10 2010-08-31 01:50:25

Chrischb
Scratcher
Registered: 2008-07-24
Posts: 1000+

Re: Tutorial: How to Eradicate Lag in Your Game

Forever-if blocks run faster than an If inside a Forever - you might want to add that.  big_smile


I fall: It's a tragedy. You fall: It's comedy.
Hmph enjoy your fall - I get a lovely spring... without pans of new leaves.

Offline

 

#11 2010-08-31 09:44:24

steppenwulf
Scratcher
Registered: 2009-07-23
Posts: 1000+

Re: Tutorial: How to Eradicate Lag in Your Game

Cool guide bro.


I'm graduating HS this April and going to college in the Fall.

Offline

 

#12 2010-08-31 10:14:28

rubiks_cube_guy238
Scratcher
Registered: 2009-07-02
Posts: 100+

Re: Tutorial: How to Eradicate Lag in Your Game

Also, use as few broadcasts as posible.


The glass is never half full nor half empty; it is twice as large as it needs to be.

Offline

 

#13 2010-08-31 10:19:51

Sunrise-Moon
Scratcher
Registered: 2009-06-27
Posts: 1000+

Re: Tutorial: How to Eradicate Lag in Your Game

Chrischb wrote:

Forever-if blocks run faster than an If inside a Forever - you might want to add that.  big_smile

That's not quite lag-related.


http://i1067.photobucket.com/albums/u427/HulKDzN/RebornBlade.png

Offline

 

#14 2010-09-03 19:16:50

j4142000
Scratcher
Registered: 2008-07-17
Posts: 17

Re: Tutorial: How to Eradicate Lag in Your Game

I really want to make a platform game,but i don't know how!One of them gave me a headache,and the other one didn't work!

Offline

 

#15 2010-09-03 19:22:09

Sunrise-Moon
Scratcher
Registered: 2009-06-27
Posts: 1000+

Re: Tutorial: How to Eradicate Lag in Your Game

j4142000 wrote:

I really want to make a platform game,but i don't know how!One of them gave me a headache,and the other one didn't work!

One of the platform games you tried to make gave you a headache? Are you asking me in particular?


http://i1067.photobucket.com/albums/u427/HulKDzN/RebornBlade.png

Offline

 

#16 2010-09-06 12:13:03

Ace-of-Spades
Scratcher
Registered: 2010-01-08
Posts: 1000+

Re: Tutorial: How to Eradicate Lag in Your Game

Sunrise-Moon wrote:

3. Try to use less scripts/combine as many scripts as possible into one script - The more scripts running at any time, the slower your game will be. If you combine a bunch of scripts into one big script, your game will be a lot smoother. Obviously, you can't do this with all scripts because of stuff like 'Wait Until <______>'.

Uh, could you check to make sure these actually work before misleading newbies with them? Here's where you're wrong. Long scripts cause more lag than many short scripts.


11110010100011010100011010101000100011011011001010111100101000110101000110101010001000110110110010101111001010001101010001101010100010001101101100101011110010100011010100011010101000100011011011001010
110101010010001010101010101010101010101010100110101010010101010010101001101011010101010010101010101

Offline

 

#17 2010-09-06 12:15:11

Sunrise-Moon
Scratcher
Registered: 2009-06-27
Posts: 1000+

Re: Tutorial: How to Eradicate Lag in Your Game

Ace-of-Spades wrote:

Sunrise-Moon wrote:

3. Try to use less scripts/combine as many scripts as possible into one script - The more scripts running at any time, the slower your game will be. If you combine a bunch of scripts into one big script, your game will be a lot smoother. Obviously, you can't do this with all scripts because of stuff like 'Wait Until <______>'.

Uh, could you check to make sure these actually work before misleading newbies with them? Here's where you're wrong. Long scripts cause more lag than many short scripts.

Oh, ok. Sorry, I'll edit it in a second.


http://i1067.photobucket.com/albums/u427/HulKDzN/RebornBlade.png

Offline

 

#18 2010-09-07 09:49:26

Locomule
Scratcher
Registered: 2009-08-24
Posts: 500+

Re: Tutorial: How to Eradicate Lag in Your Game

How do you write a project without broadcasts and Forever loops? I see both of these mentioned as "avoid this" all the time but I can't write loopless projects.


aka Pain from DragonSpires, Delrith Online, BotBattle, Urban Dead etc etc lol

Offline

 

#19 2010-09-07 11:09:45

Sunrise-Moon
Scratcher
Registered: 2009-06-27
Posts: 1000+

Re: Tutorial: How to Eradicate Lag in Your Game

Locomule wrote:

How do you write a project without broadcasts and Forever loops? I see both of these mentioned as "avoid this" all the time but I can't write loopless projects.

You should avoid them as much as possible, but you will usually use at least 2 in your projects.


http://i1067.photobucket.com/albums/u427/HulKDzN/RebornBlade.png

Offline

 

#20 2010-09-07 12:53:56

cheddargirl
Scratch Team
Registered: 2008-09-15
Posts: 1000+

Re: Tutorial: How to Eradicate Lag in Your Game

Locomule wrote:

How do you write a project without broadcasts and Forever loops? I see both of these mentioned as "avoid this" all the time but I can't write loopless projects.

About forever loops: I find that there are some cases where they can be avoided via substitution with "repeat until" loops; that way the loops don't repeat all the time throughout a project (too many loops occurring at one time can cause lag, sometimes even offline). Of course, such substitution will depend on the the project is designed.  tongue


http://i.imgur.com/8QRYx.png
Everything is better when you add a little cheddar, because when you have cheese your life is at ease  smile

Offline

 

#21 2010-09-08 02:30:05

wei2912
Scratcher
Registered: 2010-05-09
Posts: 100+

Re: Tutorial: How to Eradicate Lag in Your Game

I got a tip:

Use as less broadcasts as possible

Broadcasts are quite slow. They don't work as fast as if loops.


Waiting for Scratch 2.0...

Offline

 

#22 2010-09-08 23:35:49

Locomule
Scratcher
Registered: 2009-08-24
Posts: 500+

Re: Tutorial: How to Eradicate Lag in Your Game

I heard that broadcasts were great offline but terrible online?

I have already started doing some offline testing of my own and will post the results when finished. I never expect anything to work online as my serious projects get kinda crazy with the scripting.


aka Pain from DragonSpires, Delrith Online, BotBattle, Urban Dead etc etc lol

Offline

 

#23 2010-09-08 23:50:03

JAMBAMtheSLAM
New Scratcher
Registered: 2010-09-03
Posts: 100+

Re: Tutorial: How to Eradicate Lag in Your Game

Amazing! Should be pinned!


http://i54.tinypic.com/2s7zwxs.png

Offline

 

#24 2010-09-08 23:54:08

Harakou
Community Moderator
Registered: 2009-10-11
Posts: 1000+

Re: Tutorial: How to Eradicate Lag in Your Game

wei2912 wrote:

I got a tip:

Use as less broadcasts as possible

Broadcasts are quite slow. They don't work as fast as if loops.

Except a lot of If loops makes projects extremely slow.


http://www.blocks.scratchr.org/API.php?action=random&amp;return=image&amp;link1=http://i.imgur.com/OZn2RD3.png&amp;link2=http://i.imgur.com/duzaGTB.png&amp;link3=http://i.imgur.com/CrDGvvZ.png&amp;link4=http://i.imgur.com/POEpQyZ.png&amp;link5=http://i.imgur.com/ZKJF8ac.png

Offline

 

Board footer