5 Replies Latest reply on Jan 15, 2009 6:16 PM by Opera Rat

    Need help bad with radio script

    Opera Rat Level 1
      I'm using this script as a behavior and dragging it onto the sprite. Why do I get an error when it runs? This isn't the full script but the error is highlighted. I get list expected for handler. I have 2 radio buttons. and I name the group radio, you can forget about the pValue, and pMemberName (I do need those)

      property pMemberName, pGroup, pValue, pState

      on getPropertyDescriptionList me
      list = [:]
      addProp list, #PMemberName, [#comment: "Sprite Member", \
      #format: #member, #default: []]
      addProp list, #pValue, [#comment: "Text to Display", \
      #format: #string, #default: ""]
      addProp list, #pState, [#comment: "Initial State", \
      #format: #boolean, #default: FALSE]
      addProp list, #pGroup, [#comment: "Group Name", \
      #format: #list, #default: []]
      return list
      end

      on beginSprite me
      if pState then turnMeOn(me)
      end

      on turnMeOn me
      pState = TRUE
      sprite(me.SpriteNum).member.hilite = TRUE
      repeat with i in pGroup
      if i<> me.spriteNum then
      sendSprite(sprite i, #turnMeOff)
      end if
      end repeat
        • 1. Re: Need help bad with radio script
          Level 7
          If you use

          put pGroup just before your repeat statement what is it's value? Or you
          could put a breakpoint just before your repeat statement to check the value
          of pGroup in the debugger. It obviously wasn't entered into the data dialog
          of the behavior correctly or it is being reset somewhere.

          Secondly, when you use SendSprite I don't thing using the word sprite in
          there works. I've always used just the spriteNumber, in your case, the
          variable i, not sprite i

          Also, instead of a repeat loop your code would be cleaner if you used this.

          SendAllSprites (#turnMeOff, me.spriteNum)

          then in your turnMeOff handler just wrap it in a conditional

          on turnMeOff me, whichSpriteNotToAffect
          if me.spriteNum <> whichSpriteNotToAffect then

          your turnMeOff code

          end if
          end

          Of coure what you've done using the loop is fine but just a little less
          clean.

          --
          Craig

          "Opera Rat" <webforumsuser@macromedia.com> wrote in message
          news:gkmodh$f0c$1@forums.macromedia.com...
          > I'm using this script as a behavior and dragging it onto the sprite. Why
          > do I
          > get an error when it runs? This isn't the full script but the error is
          > highlighted. I get list expected for handler. I have 2 radio buttons.
          > and I
          > name the group radio, you can forget about the pValue, and pMemberName (I
          > do
          > need those)
          >
          > property pMemberName, pGroup, pValue, pState
          >
          > on getPropertyDescriptionList me
          > list = [:]
          > addProp list, #PMemberName, [#comment: "Sprite Member", \
          > #format: #member, #default: []]
          > addProp list, #pValue, [#comment: "Text to Display", \
          > #format: #string, #default: ""]
          > addProp list, #pState, [#comment: "Initial State", \
          > #format: #boolean, #default: FALSE]
          > addProp list, #pGroup, [#comment: "Group Name", \
          > #format: #list, #default: []]
          > return list
          > end
          >
          > on beginSprite me
          > if pState then turnMeOn(me)
          > end
          >
          > on turnMeOn me
          > pState = TRUE
          > sprite(me.SpriteNum).member.hilite = TRUE
          > repeat with i in pGroup
          > if i<> me.spriteNum then
          > sendSprite(sprite i, #turnMeOff)
          > end if
          > end repeat
          >


          • 2. Re: Need help bad with radio script
            Level 7
            I forgot to mention, to make things a bit clearer, my code suggestion
            eliminates the whole repeat loop and it also negates the error (although I'm
            sure you'd want to find out why the error is happening.)

            My approach is a bit more OOP. It allows the sprites that have the turnMeOn
            handler to determing themselves if they should run the turnMeOn code. And
            of course that portion of your code that you listed simplifies to:

            > on turnMeOn me
            > pState = TRUE
            > sprite(me.SpriteNum).member.hilite = TRUE
            > sendAllSprites(#turnMeOff, me.spriteNum)

            --
            Craig S. Wollman

            Word of Mouth Productions
            159-00 Riverside Drive West
            New York, New York 10032
            (212) 928-9581
            "Opera Rat" <webforumsuser@macromedia.com> wrote in message
            news:gkmodh$f0c$1@forums.macromedia.com...
            > I'm using this script as a behavior and dragging it onto the sprite. Why
            > do I
            > get an error when it runs? This isn't the full script but the error is
            > highlighted. I get list expected for handler. I have 2 radio buttons.
            > and I
            > name the group radio, you can forget about the pValue, and pMemberName (I
            > do
            > need those)
            >
            > property pMemberName, pGroup, pValue, pState
            >
            > on getPropertyDescriptionList me
            > list = [:]
            > addProp list, #PMemberName, [#comment: "Sprite Member", \
            > #format: #member, #default: []]
            > addProp list, #pValue, [#comment: "Text to Display", \
            > #format: #string, #default: ""]
            > addProp list, #pState, [#comment: "Initial State", \
            > #format: #boolean, #default: FALSE]
            > addProp list, #pGroup, [#comment: "Group Name", \
            > #format: #list, #default: []]
            > return list
            > end
            >
            > on beginSprite me
            > if pState then turnMeOn(me)
            > end
            >
            > on turnMeOn me
            > pState = TRUE
            > sprite(me.SpriteNum).member.hilite = TRUE
            > repeat with i in pGroup
            > if i<> me.spriteNum then
            > sendSprite(sprite i, #turnMeOff)
            > end if
            > end repeat
            >


            • 3. Need help bad with radio script
              James Newton, ACP Level 3
              pGroup is not declared in the snippet you quoted. It should be a list, and it should contain the spriteNums of the other sprites with the same behavior.

              You could use the Radio Buttons behavior which you can find here on all your bitmap sprites which act as a radio group.
              • 4. Re: Need help bad with radio script
                Level 7
                pGroup does not need to be declared in the beginSprite handler or anywhere
                else. As a matter of fact, if it were it would override the value given in
                the property inspector. When the onGetPropertyDescription handler is used,
                the property gets it's value there.

                --
                Craig

                "openspark" <webforumsuser@macromedia.com> wrote in message
                news:gknja3$knh$1@forums.macromedia.com...
                > pGroup is not declared in the snippet you quoted. It should be a list,
                > and it
                > should contain the spriteNums of the other sprites with the same behavior.
                >
                > You could use http://nonlinear.openspark.com/tips/scripts/button/ on all
                > your
                > bitmap sprites which act as a radio group.
                >


                • 5. Re: Need help bad with radio script
                  Opera Rat Level 1
                  I figured out the pValue was a string "TRUE" that is why it wasn't working. But I'm also trying your suggested changes.