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

#1 2011-11-09 22:44:47

Xzerie
New Scratcher
Registered: 2010-09-08
Posts: 11

1 Long Script VS Several tiny ones

I'm trying to put together something to see if it can be done. But before I get too far into it, I want to know if having a long 'script' is worse or better than dividing it into several smaller ones (which are triggered by broadcasts).

These if-blocks are going to really start adding up really quickly...

Offline

 

#2 2011-11-10 05:08:48

Smozzick
Scratcher
Registered: 2011-10-23
Posts: 100+

Re: 1 Long Script VS Several tiny ones

Generally I think it runs faster but there comes a point where scratch doesn't like having a script that long and can slow down in the designer. Or at least it has that point for me.


http://i50.tinypic.com/ded8m.png

Offline

 

#3 2011-11-10 05:39:10

scimonster
Community Moderator
Registered: 2010-06-13
Posts: 1000+

Re: 1 Long Script VS Several tiny ones

Depends what you're shooting for.
If you want to use as few scripts as possible, do the long one.
If you don't really care, I say it depends on your computer speed and your patience.

Offline

 

#4 2011-11-10 05:53:13

ssss
Scratcher
Registered: 2007-07-29
Posts: 1000+

Re: 1 Long Script VS Several tiny ones

scimonster wrote:

Depends what you're shooting for.
If you want to use as few scripts as possible, do the long one.
If you don't really care, I say it depends on your computer speed and your patience.

For the last one:  Wha?


Hey.  It's me SSSS, back from the dead!  smile

Offline

 

#5 2011-11-10 08:00:02

MoreGamesNow
Scratcher
Registered: 2009-10-12
Posts: 1000+

Re: 1 Long Script VS Several tiny ones

One script is (generally considered) faster, but can make it harder to program and make the code less readable.  On the other hand, I think that if you can put them all in one script, go for it!

On the other hand, using multiple scripts can cause some glitches that occur because certain scripts loop over before other ones.  In one giant script, the programmer knows what script just happened, and what variables he/she can count on as accurate.


http://images2.layoutsparks.com/1/218929/rubiks-cube-animated-rotating.gif
"Cogito ergo sum" --  I think, therefore I am

Offline

 

#6 2011-11-10 08:24:19

Xzerie
New Scratcher
Registered: 2010-09-08
Posts: 11

Re: 1 Long Script VS Several tiny ones

I'm trying to accomplish performance rather than a minimal number of scripts.

The thing in particular that I'm doing is having multiple classes/roles all crammed into the player. It is about 18 if-blocks per class, but assuming if there are like 10-15 classes, that's a bit to have constantly running in the background- just from simply walking...

I can separate each set into several smaller bunches, which would be triggered via broadcast. So that not all that extra code is having to be ran constantly.

But I'm unsure which one uses less processing, or if there is even a difference.

Offline

 

#7 2011-11-10 11:14:24

Smozzick
Scratcher
Registered: 2011-10-23
Posts: 100+

Re: 1 Long Script VS Several tiny ones

Single scripts run faster but in order, this means that if for example you had a loop in the middle of one of your bits everything would have to wait for that loop in the single script.

By using broadcasting, which takes more processing power simply because you have to do the broadcast code as well, you get more easily edited code that takes up a bit more power. Plus side is that you can run things simultaneously though, or as near as you can get to simultaneously, anyway.


http://i50.tinypic.com/ded8m.png

Offline

 

#8 2011-11-10 12:35:14

Dinoclor
Scratcher
Registered: 2010-06-10
Posts: 1000+

Re: 1 Long Script VS Several tiny ones

OK.
Last time I made a 1s1s, the designer got REALLY slow. I have never had that problem with multiple scripts.

I find multiple scripts easier to find and fix bugs, but that is just my opinion.


This is a temporary signature. It will exist until I think of something witty.

Offline

 

#9 2011-11-10 16:13:47

henley
Scratcher
Registered: 2008-06-21
Posts: 1000+

Re: 1 Long Script VS Several tiny ones

Personally, I think that several medium sized scripts would do well. Several long ones would be too laggy.

And too many scripts in general is laggy. Example.

Last edited by henley (2011-11-10 16:14:34)


"I've worked so hard for you and you give me nothing in return. Do you need help... Or do I?"

Offline

 

#10 2011-11-10 17:56:43

demosthenes
Retired Community Moderator
Registered: 2008-02-19
Posts: 1000+

Re: 1 Long Script VS Several tiny ones

Xzerie wrote:

I'm trying to accomplish performance rather than a minimal number of scripts.

The thing in particular that I'm doing is having multiple classes/roles all crammed into the player. It is about 18 if-blocks per class, but assuming if there are like 10-15 classes, that's a bit to have constantly running in the background- just from simply walking...

I can separate each set into several smaller bunches, which would be triggered via broadcast. So that not all that extra code is having to be ran constantly.

But I'm unsure which one uses less processing, or if there is even a difference.

Breaking it into broadcasts will run considerably faster. Each 5 if loops added to a forever loop can reduce the Frames Per Second by as much as 1 - 4. Having broadcasts will cut out a lot of the lag.

Also not, never have a small script that simply says:

When <greenflag> clicked
forever
if foo
bar
end

Instead, replace the if with a wait until block. For whatever reason, this speeds the program up immensely.


I've taken a long hiatus, but I still visit sometimes. Give me some time to answer any messages you post on my projects!

Offline

 

#11 2011-11-10 19:50:49

Xzerie
New Scratcher
Registered: 2010-09-08
Posts: 11

Re: 1 Long Script VS Several tiny ones

henley wrote:

Personally, I think that several medium sized scripts would do well. Several long ones would be too laggy.

And too many scripts in general is laggy. Example.

What I noticed was that they were using a lot of <when green flag clicked>, then a long list of things in <forever>.

Offline

 

#12 2011-11-10 19:55:23

jji7skyline
Scratcher
Registered: 2010-03-08
Posts: 1000+

Re: 1 Long Script VS Several tiny ones

I try to put them in one script, but it really depends on what you're trying to achieve... for example, two scripts running at the same time can check for two things at the same time but two if blocks in a forever in one script can only check for one thing at a time.


I don't know why you say goodbye, I say hello!  big_smile

Offline

 

#13 2011-11-10 20:11:21

AtomicBawm3
Scratcher
Registered: 2009-06-27
Posts: 1000+

Re: 1 Long Script VS Several tiny ones

I love to do 1s1s and I think that's usually the way to go...the problems occur when you get a long script which slows down the editing speed and such in which case, it might be better to go with multiple scripts.  However, I think that multiple scripts can lead to disorganization, overlapping scripts (i.e. one script runs when it shouldn't, messing up others), and other such things.  Multiple scripts usually need more parameters or restrictions so as to not interfere with others.


http://i50.tinypic.com/j0yw0p.jpg

Offline

 

#14 2011-11-11 08:54:48

henley
Scratcher
Registered: 2008-06-21
Posts: 1000+

Re: 1 Long Script VS Several tiny ones

Xzerie wrote:

henley wrote:

Personally, I think that several medium sized scripts would do well. Several long ones would be too laggy.

And too many scripts in general is laggy. Example.

What I noticed was that they were using a lot of [[green flag clicked] blocks], then a long list of things in some [forever] blocks.

How do you suppose I change that? By not making the project?


"I've worked so hard for you and you give me nothing in return. Do you need help... Or do I?"

Offline

 

Board footer