Drag and Drop - Chemical Formulas

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
gillilandd
Posts: 18
Joined: Wed Apr 04, 2007 7:48 pm
Contact:

Drag and Drop - Chemical Formulas

Post by gillilandd » Sat Mar 15, 2008 12:51 pm

I wish to create an exercise for my students where they click on a chemical formula (from a list of 10 or more) and drag it to one of two graphic bins labeled ionic and covalent. If the text is dropped in the correct bin they hear a "reward" sound and the formula remains in the bin. If placed in the incorrect bin the formula snaps back it it's original location while a "wrong" sound is played.
I've searched the forums/tutorials and have found some info on dragging objects but nothing that will allow me to do this.
Can anyone point me to some info on this?
Thanks,
Doug Gilliland

BvG
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1239
Joined: Sat Apr 08, 2006 1:10 pm
Contact:

Post by BvG » Sat Mar 15, 2008 1:16 pm

Altoug there is the "grab" command, for most cases it doesn't allow for enough control, but your case could be done with it i guess (even if how to do it isn't as straight forward as other stuff in Rev):

Code: Select all

on mouseDown
  grab me
end mouseDown

on mouseRelease --if the user is faster then rev
  testWithin
end mouseRelease

on mouseUp
  testWithin
end mouseUp

on testWithin
  if the loc of me is within the rectangle of button "target" then
    beep
    set the loc of me to the loc of button "target"
  end if
end testWithin
Spice the code in the "testWithin" handler up with repeat loops, if you have many targets.

Usefull docu topics:
grab command
is within operator
within() function (note: works differently then "is within")
Various teststacks and stuff:
http://bjoernke.com

Chat with other RunRev developers:
chat.freenode.net:6666 #livecode

BvG
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1239
Joined: Sat Apr 08, 2006 1:10 pm
Contact:

Post by BvG » Sat Mar 15, 2008 1:23 pm

Ah right, i forgot the snap back.

Code: Select all

local theOrigin

on mouseDown
  put the loc of me into theOrigin
  grab me
end mouseDown

on mouseRelease --neded if the user is faster then Rev
  setback
end mouseRelease

on mouseUp
 setback
end mouseUp

on setback
  set the loc of me to theOrigin
end setback
useful topics:
local command
global command
constant command
location property
Various teststacks and stuff:
http://bjoernke.com

Chat with other RunRev developers:
chat.freenode.net:6666 #livecode

gillilandd
Posts: 18
Joined: Wed Apr 04, 2007 7:48 pm
Contact:

Post by gillilandd » Tue Mar 18, 2008 10:38 am

Thanks BvG. I appreciate the script - it works fine.
D. Gilliland

Post Reply