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

#1 2007-11-25 18:07:06

makdaddy_98102
Scratcher
Registered: 2007-11-25
Posts: 4

help me understand double-pause

I have a problem with my game (based loosely on the adventures of a well-known anthro-arachnid).

http://scratch.mit.edu/projects/makdaddy_98102/59125

Confusingly, this problem occurs when you run the game inside Scratch, but not when it's run on the web.  The problem is that the game pauses for five seconds when you get the goblin with the web, and then it's supposed to continue, but it pauses for another five seconds, and only then does it continue.

It's behaving like the goblin's "if touching web" block is getting hit twice.  But you can see I've gone to some length to make sure this doesn't happen.  At one point I thought it had to do with the fact that the web gets repositioned when it hits the goblin, somehow causing the second "touching" because of the reposition.  But the problem happens even without the reposition.  From what I can understand, it actually seems to be a complicated threading type issue (like the "if touching web" block somehow gets entered twice before it has a chance to set the "freeze" variable, and the second instance somehow gets queued up for later processing), but hopefully it's something simpler.

Thanks for any help.

Michael

Offline

 

#2 2007-11-26 07:51:03

kevin_karplus
Scratcher
Registered: 2007-04-27
Posts: 1000+

Re: help me understand double-pause

I recommend changing the "if freeze=0" to "wait until freeze=0", just to make the code clearer and more efficient (all forever loops should have a wait in them, in my opinion).
But that won't fix your problem, which is a race condition.

Change your "broadcast reposition" to "broadcast reposition and wait" to make sure that repositioning is done before you unfreeze.

Offline

 

#3 2007-12-03 01:40:30

makdaddy_98102
Scratcher
Registered: 2007-11-25
Posts: 4

Re: help me understand double-pause

Thanks for the reply.  I changed "broadcast reposition" to "broadcast reposition and wait" and it fixed things.  I think I was thinking of "broadcast" as "broadcast and wait" in my mind.  I didn't notice the alternative.  Now I know.

Offline

 

Board footer