Drag and Drop Help.

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
asemitruck
Posts: 3
Joined: Tue Dec 18, 2018 8:08 am

Drag and Drop Help.

Post by asemitruck » Tue Dec 18, 2018 8:19 am

I have been working on a drag and drop quiz and have run into a problem. I have been working on learning how to count in spanish. I have the 10 numbers in a group on the side called "numbers" and would like to grab the text from my group "numbers" and then be able to put them in a field called "answers." I am able to put them into the field but not sure how to make it the objects look as if they go from line 1 of the field all the way to line 10. This is my code that I have so far. I am still new to livecode and learning the ropes:) I know that I am missing some code and would appreciate the help. Thanks!

on mouseDown
grab the target
put the short name of the target into tVar
end mouseDown

on mouseUp
repeat with x = 1 to number of fields in group "numbers"
if within(fld "numbers", the loc of the target) then
move fld tVar of group "numbers" to the loc of line x of fld "numbers" in 10 ticks without waiting
disable fld tVar of me
add 1 to x
else
set the loc of fld gBox of me to the startLoc of fld gBox of me
end if
end repeat
end mouseUp

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9655
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Drag and Drop Help.

Post by dunbarx » Tue Dec 18, 2018 3:29 pm

Hi.

We can do this, but I am not sure I understand what you want to do.

When you say you have a "group" on the side, what does that mean? Is it a group of fields? Is it simply several lines of text within a field?

And this:
but not sure how to make it the objects look as if they go from line 1 of the field all the way to line 10
What does that mean? Please give a more detailed instructions. Or wait for someone smarter to chime in.

Remember, we can do this. Write back...

Craig Newman

asemitruck
Posts: 3
Joined: Tue Dec 18, 2018 8:08 am

Re: Drag and Drop Help.

Post by asemitruck » Tue Dec 18, 2018 3:58 pm

Hey dunbark, thanks for the reply. So it is a group of 10 separate fields with the goal to place them within the empty field reflecting the answer field. I have attached a screenshot below and hopefully, you understand my explanation. Ultimately I would like to make a script that will go through and check and make sure the answers are correct by changing the textColor to green if it is correct and red if it is incorrect.
Attachments
Screen Shot 2018-12-18 at 7.54.42 AM.png

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9655
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Drag and Drop Help.

Post by dunbarx » Tue Dec 18, 2018 5:28 pm

Ah.

So you can:

Code: Select all

on mouseDown
   if "field" is in the name of the target then grab the target
end mouseDown

on mouseUp
      put target & return after fld yourTestField
end mouseUp
This should get the contents of each field you drag into a return delimited list. You will want to return the dragged field back to its original location, no? Once all that is done, you can test the contents of the list to see if the lines are in the correct order.

Craig

asemitruck
Posts: 3
Joined: Tue Dec 18, 2018 8:08 am

Re: Drag and Drop Help.

Post by asemitruck » Tue Dec 18, 2018 6:59 pm

Thank you so much! I have the rest figured out from here :)

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9655
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Drag and Drop Help.

Post by dunbarx » Tue Dec 18, 2018 7:58 pm

Good.

I neglected to suggest that the above handlers should be placed in the card script, and that you may want to further restrict the grab only to the fields that you want.

Craig

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”