Problem moving objects

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
Newbie4
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 332
Joined: Sun Apr 15, 2012 1:17 am
Contact:

Problem moving objects

Post by Newbie4 » Sat Oct 27, 2012 4:30 am

I am working on a seating chart and am having trouble allowing the user to move the seats. Right now the seats are placed in a set arrangement and locked into position. You can move the students from seat to seat.
I am trying to make the seats moveable so that the user can change the arrangement of the chairs. I added the following code

Code: Select all

command makeSeatsMoveable
  repeat with x = 1 to numSeats
      set the opaque of graphic ("seat_" &  x) to true
      set the lockLoc of graphic ("seat_" &  x) to false
      set the showName of graphic ("seat_" &  x) to true
   end repeat
end makeSeatsMoveable
In edit mode, I can move the seats. On the card, I added

Code: Select all

on mouseDown
grab me
end mouseDown
but when I run it, I get the error message:
card "seatingChart" execution error at line 321 (grab: can't find object), char 1

Any ideas why? I have used "grab me" before.
Is there another way to do this?

Thanks
Cyril Pruszko
https://sites.google.com/a/pgcps.org/livecode/
https://sites.google.com/a/setonhs.org/app-and-game-workshop/home
https://learntolivecode.com/

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4172
Joined: Sun Jan 07, 2007 9:12 pm

Re: Problem moving objects

Post by bn » Sat Oct 27, 2012 9:44 am

If you put your mouseDown handler into the card script then me refers to the card. Not anything else.

try this:

Code: Select all

on mouseDown
   if the target contains "seat_" then 
      grab the target
   else
      pass mouseDown
   end if
end mouseDown
be aware though that grab also works on objects that have their lockloc set to true.

in your handler makeSeatsMoveable the variable numSeats is not filled.

Kind regards
Bernd

Kind regards
Bernd

Newbie4
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 332
Joined: Sun Apr 15, 2012 1:17 am
Contact:

Re: Problem moving objects

Post by Newbie4 » Sat Oct 27, 2012 10:46 pm

That was it. Thank you.
I have the mouseDown handler on the card to handle moving the students. It works. That is why I could not figure out why moving the seats did not work. Your code solved it. Thank you

I do not under stand your statement
in your handler makeSeatsMoveable the variable numSeats is not filled.
I do have the numSeats set to a number before this. Is that what you mean by filled?

Thank you again for your help
Cyril Pruszko
https://sites.google.com/a/pgcps.org/livecode/
https://sites.google.com/a/setonhs.org/app-and-game-workshop/home
https://learntolivecode.com/

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: Problem moving objects

Post by Mark » Sat Oct 27, 2012 11:02 pm

Hi,

Perhaps, numSeats is a global variable? That would explain it.

Kind regards,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4172
Joined: Sun Jan 07, 2007 9:12 pm

Re: Problem moving objects

Post by bn » Sat Oct 27, 2012 11:03 pm

I do have the numSeats set to a number before this. Is that what you mean by filled?
Yes that is what I was wondering. In the handler it is not filled, nor is it passed as a parameter. So it must be a global or script local variable.

I usually prepend local variables with a t, script local variables with an s and global variables with a g. This helps me to recall what the scope of the variable is.
You might want to have a look at Richard Gaskin's site: http://www.fourthworld.com/embassy/arti ... style.html

Anyway, glad it works.

Kind regards
Bernd

Post Reply