Re: lingo-l not statement

2002-01-25 Thread Andreas Gaunitz P11

hey list --
simple question.. i thought i saw something a while ago... a simple toggle
using a not to swap sprites but i am really getting the syntax wrong. can
anyone help? heres the code

on mouseUp me
   member(music_on).name = not member(music_off).name
end

i know i am not calling the sprites right but i have spent a good portion of
the last 2 hours looking for where i saw the reference and have come up
empty. thanks


Note that the above statement using the Name property will not switch 
cast members, only change the members' names.


About not:
Not can only switch between 1 and 0 (True and False). not will 
work best with statements that toggles True/False conditions, like

on exitFrame me
   the visible of sprite(me.spriteNum) =\
   not the visible of sprite(me.spriteNum) -- Blinking sprite!

   go the frame
end


However, if you know you are using members 10 and 11 you could create 
a True/ Flase condition by offsetting the member numbers:

on mouseDown me
   sprite(me.spriteNum).member = \
 not (sprite(me.spriteNum).member.memberNum - 10) + 10 -- Mem 10 or 11
end


The problem is that you need to hard-code the member number. If you 
want a more general script (that works with any combination of 2 
members in sequence) here's a modified version of JHM's suggestion:

on mouseDown me
   sprite(me.spriteNum).member = sprite(me.spriteNum).memberNum\
   + [1, -1][sprite(me.spriteNum).memberNum mod 2 + 1] -- Toggling member num
end


-A.
[To remove yourself from this list, or to change to digest mode, go to 
http://www.penworks.com/lingo-l.cgi  To post messages to the list, email 
[EMAIL PROTECTED]  (Problems, email [EMAIL PROTECTED]). Lingo-L is for 
learning and helping with programming Lingo.  Thanks!]



RE: lingo-l not statement

2002-01-25 Thread Carol Mahaffy

this worked perfectly! thanks guys for the input. Is this considered like a
push or pop in a list? I am asking that beasuse my strength is in
javascript and i would have never thought to use that logic for solving
this. thanks again guys
-- carol

 --
 From: Daniel Plaenitz
 Reply To: [EMAIL PROTECTED]
 Sent: Friday, January 25, 2002 6:30 AM
 To:   [EMAIL PROTECTED]; Lingo List (E-mail)
 Subject:  Re: lingo-l not statement
 
 At 18:32 24.01.2002 -0500, Carol Mahaffy wrote:
 hey list --
 simple question.. i thought i saw something a while ago... a simple
 toggle
 using a not to swap sprites but i am really getting the syntax wrong.
 can
 anyone help? heres the code
 
 on mouseUp me
member(music_on).name = not member(music_off).name
 end
 
 i know i am not calling the sprites right but i have spent a good portion
 of
 the last 2 hours looking for where i saw the reference and have come up
 empty. thanks
 --carol
 
 Carol,
 
 supposed you have named the members 0 and 1 you might use a behavior 
 like this one:
 
 ---
 property mySprite
 
 on beginsprite me
mySprite = sprite(me.spritenum)
 end
 
 on mouseUp me
mySprite.member = \
member([0,1][(not([0,1].getPos(mysprite.member.name)-1)+1)])
 end
 ---
 
 best regards
 
 daniel plaenitz
 [To remove yourself from this list, or to change to digest mode, go to
 http://www.penworks.com/lingo-l.cgi  To post messages to the list, email
 [EMAIL PROTECTED]  (Problems, email [EMAIL PROTECTED]). Lingo-L
 is for learning and helping with programming Lingo.  Thanks!]
 
 
[To remove yourself from this list, or to change to digest mode, go to 
http://www.penworks.com/lingo-l.cgi  To post messages to the list, email 
[EMAIL PROTECTED]  (Problems, email [EMAIL PROTECTED]). Lingo-L is for 
learning and helping with programming Lingo.  Thanks!]



RE: lingo-l not statement

2002-01-25 Thread Irv Kalb

Carol, et al,

While these solutions do work, they are not very clear about what is 
really going on.  I've always felt that it is much more important to 
write code that can be read easily both by yourself and by others 
that may follow, than to try to write an obscure single line that 
works, but is unreadable.  It is also a good goal to write code that 
is generic, that is, it will work in many cases.

You are basically talking about a toggle button - a button with two 
states.  There are two parts to this, what you see on the screen, and 
the internal state of the button.  First thing to do is to come up 
with a naming convention for the two states, for example Some base 
name on and Some base name off.  Given a naming convention like 
this, here is a start at the behavior (with minor testing):

property pMemberOn
property pMemberOff
property pState -- TRUE for on, FALSE for off
property spriteNum

on beginSprite me
-- First determine if we are starting in the on or off state
-- and find the matching alternate state button
   theName = sprite(spriteNum).member.name
   theBaseName = word 1 of theName
   theCurrentState = word 2 of theName
   if theCurrentState = on then
 pMemberOn = sprite(spriteNum).member
 pMemberOff = member(theBaseName   off)
 pState = TRUE
   else
 pMemberOff = sprite(spriteNum).member
 pMemberOn = member(theBaseName   on)
 pState = 0
   end if
end

on mouseUp me
   -- Now toggle the state and show the new button on the screen
   pState = not(pState)
   if pState then
 sprite(spriteNum).member = pMemberOn
   else
 sprite(spriteNum).member = pMemberOff
   end if
   -- now send out a special call to a sibling sprite to say that the 
toggle was hit.
   sendSprite(spriteNum, #mHitToggleButton, pState)
end

This way you can re-use this same behavior on every toggle button in 
your project.

When you attach this behavior, then you need to attach another 
behavior to say what should be done when this button is hit. 
Something like this:

on mHitToggleButton me, TrueOrFalse
   if TrueOrFalse
  -- do something here
   else
  -- do something else here
   end if
end


Hope this helps.

Irv


At 11:19 AM -0500 1/25/02, Carol Mahaffy wrote:
this worked perfectly! thanks guys for the input. Is this considered like a
push or pop in a list? I am asking that beasuse my strength is in
javascript and i would have never thought to use that logic for solving
this. thanks again guys
-- carol

  --
  From:   Daniel Plaenitz
  Reply To:   [EMAIL PROTECTED]
  Sent:   Friday, January 25, 2002 6:30 AM
  To: [EMAIL PROTECTED]; Lingo List (E-mail)
  Subject:Re: lingo-l not statement

  At 18:32 24.01.2002 -0500, Carol Mahaffy wrote:
  hey list --
  simple question.. i thought i saw something a while ago... a simple
  toggle
  using a not to swap sprites but i am really getting the syntax wrong.
  can
  anyone help? heres the code
  
  on mouseUp me
 member(music_on).name = not member(music_off).name
  end
  
  i know i am not calling the sprites right but i have spent a good portion
  of
  the last 2 hours looking for where i saw the reference and have come up
  empty. thanks
  --carol

  Carol,

  supposed you have named the members 0 and 1 you might use a behavior
  like this one:

  ---
  property mySprite

  on beginsprite me
 mySprite = sprite(me.spritenum)
  end

  on mouseUp me
 mySprite.member = \
 member([0,1][(not([0,1].getPos(mysprite.member.name)-1)+1)])
  end
  ---

  best regards

  daniel plaenitz
  [To remove yourself from this list, or to change to digest mode, go to
  http://www.penworks.com/lingo-l.cgi  To post messages to the list, email
  [EMAIL PROTECTED]  (Problems, email [EMAIL PROTECTED]). Lingo-L
  is for learning and helping with programming Lingo.  Thanks!]


[To remove yourself from this list, or to change to digest mode, go 
to http://www.penworks.com/lingo-l.cgi  To post messages to the 
list, email [EMAIL PROTECTED]  (Problems, email 
[EMAIL PROTECTED]). Lingo-L is for learning and helping with 
programming Lingo.  Thanks!]


-- 

Lingo / Director / Shockwave development for all occasions. 
  
   (Home-made Lingo cooked up fresh every day just for you.)
[To remove yourself from this list, or to change to digest mode, go to 
http://www.penworks.com/lingo-l.cgi  To post messages to the list, email 
[EMAIL PROTECTED]  (Problems, email [EMAIL PROTECTED]). Lingo-L is for 
learning and helping with programming Lingo.  Thanks!]



RE: lingo-l not statement

2002-01-25 Thread Jakob Hede Madsen

At 12:38 -0800 25/01/02, Irv Kalb wrote:
Carol, et al,

While these solutions do work, they are not very clear about what is 
really going on.  I've always felt that it is much more important to 
write code that can be read easily both by yourself and by others 
that may follow, than to try to write an obscure single line that 
works, but is unreadable.  It is also a good goal to write code that 
is generic, that is, it will work in many cases.

Couldn't agree more... would've never used such a single line beast myself  ;-)

I also store the stateMembers in a beginSprite handler, usually in 
one property list, but while the member-naming scheme may be 
pedadagogic and communicative, I use the sequence of adjacent 
members to signify their state.
So the member actually attached to the button is the default state, 
and the next is down, or whatever and so forth.

This can even be quite self-documenting:

tNummbr = pSprite.member.number
repeat with tState in [#up, #down, #left, #right, #exploding]
   pStateMemberPList[tState] = member tNummbr
   tNummbr = tNummbr + 1
end repeat

The later on:

pSprite.member = pStateMemberPList[pCurrentState]

This suits my style better than the rigorous naming.

Decide on your button-conventions early, and be consistent.

Jakob
[To remove yourself from this list, or to change to digest mode, go to 
http://www.penworks.com/lingo-l.cgi  To post messages to the list, email 
[EMAIL PROTECTED]  (Problems, email [EMAIL PROTECTED]). Lingo-L is for 
learning and helping with programming Lingo.  Thanks!]