Page 1 of 1

Problem moving objects

Posted: Sat Oct 27, 2012 4:30 am
by Newbie4
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

Re: Problem moving objects

Posted: Sat Oct 27, 2012 9:44 am
by bn
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

Re: Problem moving objects

Posted: Sat Oct 27, 2012 10:46 pm
by Newbie4
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

Re: Problem moving objects

Posted: Sat Oct 27, 2012 11:02 pm
by Mark
Hi,

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

Kind regards,

Mark

Re: Problem moving objects

Posted: Sat Oct 27, 2012 11:03 pm
by bn
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