Passing a graphic to a function
Posted: Fri May 31, 2013 5:08 am
Hi. I am trying to write some simple functions to get the x and y coordinate of an input, and then eventually find the distance between two inputs. Here is the script. The script is doing other things. But it is moving a graphic, and then getting reporting the x and y coordinate.
This script runs fine.
But if instead of using the target, I use the explicit graphic in question, I get an error.
I get the following error:
Of course I want to know where I went wrong. Because the target evaluates to graphic "Recangle1" in this case?
But I am passing an object, a graphic, to a function. And it worked as expected when using "the target." And I didn't give it a second thought. Until I tried to pass a graphic using different syntax.
I would like to know what is the proper way to pass objects such as graphics to a function? And can you recommend any resources that address this?
Muchas Gracias.
Code: Select all
on moveRectDist x
set movespeed to 300
move the target to the loc of grc ("Rectangle" & x)
put getX(the target) into field "Field1"
put getY(the target) into field "Field2"
end moveRectDist
function getX input
return item 1 of the loc of input
end getX
function getY input
return item 2 of the loc of input
end getY
But if instead of using the target, I use the explicit graphic in question, I get an error.
Code: Select all
on moveRectDist x
set movespeed to 300
move the target to the loc of grc ("Rectangle" & x)
put getX(grc "Rectangle1") into field "Field1"
put getY(the target) into field "Field2"
end moveRectDist
Code: Select all
Type Chunk: source is not a container
Object card id 1002
Line put getX(graphic "Rectangle1") into field "Field1"
Hint moveRectDist
But I am passing an object, a graphic, to a function. And it worked as expected when using "the target." And I didn't give it a second thought. Until I tried to pass a graphic using different syntax.
I would like to know what is the proper way to pass objects such as graphics to a function? And can you recommend any resources that address this?
Muchas Gracias.