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

#1 2008-07-25 20:54:25

fabi85
Scratcher
Registered: 2008-05-13
Posts: 27

Slow calls of broadcasts?

Hi

I'm working on a big project (Until now over 1000 Scripts and 200 Sprites). I try to use many broadcasts to avoid a mess in the code. Now I have around 80 different broadcasts. Now I noticed that a test of the game which I've uploaded, started to lag every time a broadcast is done. While the spaceshooting part it's very annoying. Do you believe, if I reduce the amount of broadcasts (maybe around 50) and work more with big "methods" I could solve this problem, or is the problem somewhere else? Maybe the amount of the sprites? But that wouldn't explain the lags when a broadcast is called.
Please help, I put so much work in this and now it's nearly unplayable.
This is the project:
http://scratch.mit.edu/projects/fabi85/225017


Greets

Last edited by fabi85 (2008-07-25 20:55:12)

Offline

 

#2 2008-07-25 21:05:02

Lanie
Scratcher
Registered: 2008-02-03
Posts: 1000+

Re: Slow calls of broadcasts?

I think it would work if you did not have so many broadcast, maybe you can do half broadcast and some bigger methods and that should make a big difference. But this game is great  i downloaded it and I have to say Impressive, if you dont mind me asking how long have you been working on this?

Offline

 

#3 2008-07-25 21:05:13

Cyclone103
Scratcher
Registered: 2008-03-20
Posts: 500+

Re: Slow calls of broadcasts?

Do you think you are using efficient coding? Over 1000 scripts is a lot! A way to simplify is to create a variable called "broadcast" and have it change instead of broadcasting. A simple "when green flag clicked - forever - wait until (broadcast=___) perform action____"
and if certain broadcasts are sequential then after the action part of the script, have the next part "wait until (broadcast=____)" and it should work just fine, and any sprite can change the number of the broadcast variable back after it has performed its action, and set it to zero. Would you like to see an example?  I can upload a project which will show this visually if you like.


All your base are belong to us

Offline

 

#4 2008-07-25 21:31:09

fabi85
Scratcher
Registered: 2008-05-13
Posts: 27

Re: Slow calls of broadcasts?

Cyclone103 wrote:

A way to simplify is to create a variable called "broadcast" and have it change instead of broadcasting. A simple "when green flag clicked - forever - wait until (broadcast=___) perform action____"

I have already used this method. But I decided to make more broadcasts to organize the code. I replaced a few of this variables with the broadcast method, because I thought lots of "wait until" need a lot of CPU-time (because "wait until" don't wait, it checks all the time if the "until" it's true). And a broadcast is one method-call. It should be much better. But obviously it's not. Very confusing...

Cyclone103 wrote:

Would you like to see an example?  I can upload a project which will show this visually if you like.

Thanks, but your explanation was good.

Lanie wrote:

I think it would work if you did not have so many broadcast, maybe you can do half broadcast and some bigger methods and that should make a big difference. But this game is great  i downloaded it and I have to say Impressive, if you dont mind me asking how long have you been working on this?

Since 3month. Many hours  wink

Offline

 

#5 2008-07-25 21:32:15

Lanie
Scratcher
Registered: 2008-02-03
Posts: 1000+

Re: Slow calls of broadcasts?

Wow thats long usually i will spend 3 days on a project unless its collaborative work  but usually many hours in the day, well good luck to you

Offline

 

#6 2008-07-25 21:35:36

Cyclone103
Scratcher
Registered: 2008-03-20
Posts: 500+

Re: Slow calls of broadcasts?

Well, I might make and upload that project anyway, since it might help other users too. Sorry to hear it is not working perfectly for you, although I did not mind the lag. Your game is very fun!


All your base are belong to us

Offline

 

#7 2008-07-25 21:46:12

fabi85
Scratcher
Registered: 2008-05-13
Posts: 27

Re: Slow calls of broadcasts?

Cyclone103 wrote:

Well, I might make and upload that project anyway, since it might help other users too.

Yes, you're right! Write the link from your project here, as soon as you have it.

Cyclone103 wrote:

Sorry to hear it is not working perfectly for you, although I did not mind the lag. Your game is very fun!

No problem! I have time... I think before I continue, I redesign the code to remove the broadcasts.

Greets

Offline

 

#8 2008-08-06 06:26:57

fabi85
Scratcher
Registered: 2008-05-13
Posts: 27

Re: Slow calls of broadcasts?

I think I know what the problem is with the slow calls of broadcasts. Probably the broadcasts are implemented with the Observer-Pattern (search for it in Wikipedia). If that is true than the problem is not how many different broadcasts exist, the problem is how many Objects receives the broadcast. If I could minimize the receivers of the broadcast, the calls should be faster.

Offline

 

Board footer