7 Replies Latest reply on Apr 30, 2007 9:38 PM by Newsgroup_User

    IF AND multiple statements?

    rlync04
      I'm trying to program up a multiple IF statement, where I want to check the condition of a number of sprites. Here's what i got:

      if sprite(5).visible=TRUE then
      sprite(6).visible=TRUE
      sprite(7).visible=TRUE
      sprite(8).visible=TRUE
      go to "Win"

      I want my lingo to check the status of all the sprites and then if they are all true I want them to go to "Win", but at the minute it's only checking that of 5. If I put 'then' at the end of each statement I get an error....any ideas

      Ronan
        • 1. Re: IF AND multiple statements?
          Level 7
          rlync04 wrote:
          > I'm trying to program up a multiple IF statement, where I want to
          > check the condition of a number of sprites. Here's what i got:
          >
          > if sprite(5).visible=TRUE then
          > sprite(6).visible=TRUE
          > sprite(7).visible=TRUE
          > sprite(8).visible=TRUE
          > go to "Win"
          >
          > I want my lingo to check the status of all the sprites and then if
          > they are all true I want them to go to "Win", but at the minute it's
          > only checking that of 5. If I put 'then' at the end of each statement
          > I get an error....any ideas

          a=true
          repeat with i=5 to 8
          a=a and sprite(i).visible
          end repeat
          if a then go "Win"

          Andrew


          • 2. Re: IF AND multiple statements?
            Level 7
            Andrews code certainly will work but is might be a bit much for you. If
            that's the case:

            flag = TRUE
            repeat with spr = 5 to 8
            if sprite (spr).visible = FALSE then
            flag = FALSE
            end if
            end repeat
            if flag = TRUE then
            go to "Win"
            end if

            Then again, mine might not be that simple either.


            --
            Craig Wollman
            Lingo Specialist
            Word of Mouth Productions
            212-928-9581

            www.wordofmouthpros.com
            "rlync04" <webforumsuser@macromedia.com> wrote in message
            news:f07vdg$6te$1@forums.macromedia.com...
            > I'm trying to program up a multiple IF statement, where I want to check
            > the
            > condition of a number of sprites. Here's what i got:
            >
            > if sprite(5).visible=TRUE then
            > sprite(6).visible=TRUE
            > sprite(7).visible=TRUE
            > sprite(8).visible=TRUE
            > go to "Win"
            >
            > I want my lingo to check the status of all the sprites and then if they
            > are
            > all true I want them to go to "Win", but at the minute it's only checking
            > that
            > of 5. If I put 'then' at the end of each statement I get an error....any
            > ideas
            >
            > Ronan
            >
            >


            • 3. Re: IF AND multiple statements?
              Level 7
              Andrew Morton wrote:

              > a=true
              > repeat with i=5 to 8
              > a=a and sprite(i).visible
              > end repeat
              > if a then go "Win"
              >
              > Andrew

              Andrew - I thought I was a pretty good coder, but I see I obviously
              don't know everything. I would have done it the same way Craig showed,
              but yours looks like it's probably a lot more efficient. Can you
              explain the logic of the line that reads a=a and sprite(i).visible ?

              Thanks,
              Matt
              • 4. Re: IF AND multiple statements?
                Level 7
                Word One - Denver wrote:
                > Andrew Morton wrote:
                >
                >> a=true
                >> repeat with i=5 to 8
                >> a=a and sprite(i).visible
                >> end repeat
                >> if a then go "Win"
                >
                > Andrew - I thought I was a pretty good coder, but I see I obviously
                > don't know everything. I would have done it the same way Craig
                > showed, but yours looks like it's probably a lot more efficient. Can
                > you explain the logic of the line that reads a=a and
                > sprite(i).visible ?

                Variable a is a boolean, and sprite(i).visible is a boolean. "and" operates
                on two boolean values to give a boolean result. If <something> then... tests
                the boolean value of <something>.

                There is no /need/ to write "if sprite(i).visible=true then..." but is does
                make it easier to read, even if it's more work for the computer.

                Once a sprite(i).visible has been tested and found to be false, a becomes
                false and cannot be changed back to true by the "and" operator.

                If there had been a lot more sprites to test, I might have put in a an early
                exit clause, like this:

                a=true
                repeat with i=1 to 500
                a=a and sprite(i).visible
                if not(a) then exit repeat
                end repeat
                if a then go "Win"

                HTH

                Andrew


                • 5. Re: IF AND multiple statements?
                  Level 7
                  Andrew's code is elegant and efficient. The only think that's worth
                  considering in any coding situation is who and when the code might need to
                  be reviewed, changed or appended. I was once hired by Sony to work on a
                  simulation of an interactive cable TV program. I was taking over the
                  project and was adding features to the previous programmers work. The
                  previous programmer wrote an incredibly complex object oriented program. I
                  spent 40 hours trying to get into his code and never did figure it out.
                  Fortunately Sony was compassionate and paid me for the time and understood
                  the situation. I consider myself a pretty experienced Lingo coder but
                  deciphering the previously written code was proved impossible for me. Did I
                  mention there were no comments?

                  I could have made my point in fewer words and that point is sometimes a bit
                  less efficient code will save time and money in the long run whether the
                  original programmer is revisiting a project or a new programmer is.
                  Director provides so many ways to get a job done and it's worth considering
                  the various options.

                  Craig (possibly a bit jealous of Andrew's solution)

                  --
                  Craig Wollman
                  Lingo Specialist
                  Word of Mouth Productions
                  212-928-9581

                  www.wordofmouthpros.com
                  "Andrew Morton" <akm@in-press.co.uk.invalid> wrote in message
                  news:f0pkli$3kl$1@forums.macromedia.com...
                  > Word One - Denver wrote:
                  >> Andrew Morton wrote:
                  >>
                  >>> a=true
                  >>> repeat with i=5 to 8
                  >>> a=a and sprite(i).visible
                  >>> end repeat
                  >>> if a then go "Win"
                  >>
                  >> Andrew - I thought I was a pretty good coder, but I see I obviously
                  >> don't know everything. I would have done it the same way Craig
                  >> showed, but yours looks like it's probably a lot more efficient. Can
                  >> you explain the logic of the line that reads a=a and
                  >> sprite(i).visible ?
                  >
                  > Variable a is a boolean, and sprite(i).visible is a boolean. "and"
                  > operates on two boolean values to give a boolean result. If <something>
                  > then... tests the boolean value of <something>.
                  >
                  > There is no /need/ to write "if sprite(i).visible=true then..." but is
                  > does make it easier to read, even if it's more work for the computer.
                  >
                  > Once a sprite(i).visible has been tested and found to be false, a becomes
                  > false and cannot be changed back to true by the "and" operator.
                  >
                  > If there had been a lot more sprites to test, I might have put in a an
                  > early exit clause, like this:
                  >
                  > a=true
                  > repeat with i=1 to 500
                  > a=a and sprite(i).visible
                  > if not(a) then exit repeat
                  > end repeat
                  > if a then go "Win"
                  >
                  > HTH
                  >
                  > Andrew
                  >


                  • 6. Re: IF AND multiple statements?
                    Level 7
                    General comments:-

                    Craig wrote:
                    > Andrew's code is elegant and efficient. The only think that's worth
                    > considering in any coding situation is who and when the code might
                    > need to be reviewed, changed or appended.
                    <snip 40 hours of scratching head>
                    > I consider myself a pretty experienced Lingo coder but deciphering
                    > the previously written code was proved impossible for me. Did I
                    > mention there were no comments?

                    That's why I wrote:
                    >> There is no /need/ to write "if sprite(i).visible=true then..." but
                    >> is does make it easier to read, even if it's more work for the
                    >> computer.

                    However, having re-coded something from Lingo into VB.NET, I found that
                    instead of taking 10-15 minutes to run (when it didn't fall over on the
                    first or second run) it took two seconds, so IMO the less you can give Lingo
                    to do, the better. On the third hand, not everything is really that
                    time-critical that it's worth worrying about.

                    Craig wrote:
                    > I could have made my point in fewer words and that point is sometimes
                    > a bit less efficient code will save time and money in the long run
                    > whether the original programmer is revisiting a project or a new
                    > programmer is. Director provides so many ways to get a job done and
                    > it's worth considering the various options.
                    >
                    > Craig (possibly a bit jealous of Andrew's solution)

                    <fx:blush>

                    It's also important to write comments that you'll understand *yourself* next
                    year, perhaps even writing the comments as pseudo-code /before/ writing the
                    code. And use meaningful variable names - a practice I blithesomely ignore:
                    for me, i,j,k are always indexes for loops, s and t are temporary strings,
                    a,b,c... tend to be integers or parameters, and x,y,z are non-integers.
                    That's from the days of having variable names which /had/ to be in the range
                    A1...Z9. (And I'm not very good at typing quickly anyway.)

                    Also, write code simply to start off with, just one simple step per line,
                    then when you're meant to be doing something you'd rather put off you can go
                    back to the code and turn it into a one-liner. That's where it's a good idea
                    to leave the original, simple code in as comments.

                    Andrew


                    • 7. Re: IF AND multiple statements?
                      Level 7
                      Andrew,

                      Sorry for such a delayed THANK YOU... but THANK YOU for your
                      explanation. I learn more every day!

                      -Matt