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

#1 2010-08-02 01:04:46

MabonBaladevaKain
Scratcher
Registered: 2010-07-25
Posts: 80

What's the technical reason for this?

So umm ... Why can't the "While" loops (Forever IF) be stacked under eachother?

Shouldn't I be able to say
While this is happening ... do this.
But While this is happening ... do this other thing.
?

Instead of just While this is happening, and While this an this an this is happening too
... do this.

Or am I mistaking how the Forever Ifs function?

<shrugs>

Offline

 

#2 2010-08-02 01:50:31

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

Re: What's the technical reason for this?

The Forever if block is a loop that never ends - but it only performs its stuff when the boolean is true. You can't stack Forever ifs inside each other, because only the first one would get to be used.  smile


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

Offline

 

#3 2010-08-02 01:53:47

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

Re: What's the technical reason for this?

Do you mean placing a Forever If inside of another one or place it underneath?
If you want something similar to placing them in sequence, you can put an If Else block inside of a Forever loop. Though I'm not too sure, I've never used Forever If blocks before.

A ninja!

Last edited by Ace-of-Spades (2010-08-02 02:21:40)


11110010100011010100011010101000100011011011001010111100101000110101000110101010001000110110110010101111001010001101010001101010100010001101101100101011110010100011010100011010101000100011011011001010
110101010010001010101010101010101010101010100110101010010101010010101001101011010101010010101010101

Offline

 

#4 2010-08-02 05:53:57

helltank
Scratcher
Registered: 2010-05-21
Posts: 1000+

Re: What's the technical reason for this?

Or you can:

Forever
Forever if:<blah>
<blah>
*end Forever if*
Forever if: <second blah>
<second blah>
*end forever if*
*end forever*


Error:Signature could not load. Please wait for an indefinite amount of time, until you realize you're gullible and go off to look for another potentially interesting signature to stare at.

Offline

 

#5 2010-08-02 07:48:55

colorfusion
Scratcher
Registered: 2009-10-03
Posts: 500+

Re: What's the technical reason for this?

What do you mean?
Forever blocks never end, so it will never get to the second thing.
If you want "While this is happening ... do this.But While this is happening ... do this other thing." you just do:

http://i28.tinypic.com/2r2myko.jpg


This is what the forever if block does:

http://i25.tinypic.com/2ypcae0.jpg

Although it may seem like it since if keeps on doing the thing, it does not mean "If this, do this forever", It means "Keep on checking this, and if its true do it"

Last edited by colorfusion (2010-08-02 07:58:00)

Offline

 

#6 2010-08-02 11:24:22

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

Re: What's the technical reason for this?

Jonathanpb is right. Forever If is not a while block, because it will always check to see if its boolean is true, whereas While will continue on after its boolean is false.

Code:

Forever if <boolean>
   blocks
EndForeverIf

=

Forever
   If <boolean>
      blocks
   EndIf
EndForever

Code:

While <boolean>
   blocks
EndWhile

=

Repeat Until <NOT <boolean> >
   blocks
EndRepeatUntil

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

 

#7 2010-08-02 21:39:42

MabonBaladevaKain
Scratcher
Registered: 2010-07-25
Posts: 80

Re: What's the technical reason for this?

The problem is that I need something to know right away when a key is pressed.
I've been using the if else block within a forever block, but the problem with that is that in a long script a delay is created before the character moves when a button is pressed. I've fixed it only by creating duplicate code that checks if the key is pressed every so often throughout the script. I'd really like to find a better way and remove the duplicate code while still retaining the smooth motion functionality.

There is an idle animation (not just one frame standing still), a walking animation (this works smoothly if I have only one frame in the walking anim instead of two),
directions left and right, and an attack sequence that I have working currently.

Offline

 

#8 2010-08-03 00:05:45

MabonBaladevaKain
Scratcher
Registered: 2010-07-25
Posts: 80

Re: What's the technical reason for this?

Nevermind, I'm an idiot. :p ... I figured out a shorter way.
Still had to use a little bit of duplicate code though ...
Which leads me to another question ... I'll make a new post for it.

Offline

 

Board footer