Page 1 of 1
Working with coordinates
Posted: Mon Jun 17, 2013 5:10 pm
by MaxV
Hi,
I want to work with coordinates (or
points) like
75,58.
Why this works?
Code: Select all
set the loc of graphic "rectangle" to 100,70
and this not?
Code: Select all
set item 2 of the loc of graphic "rectangle" to 70
How can I act directly to Y coordinate?
Re: Working with coordinates
Posted: Mon Jun 17, 2013 5:34 pm
by Klaus
Hi Max,
only in 3 steps:
1. put loc into var
2. modify the var
3. set loc to var
Best
Klaus
Re: Working with coordinates
Posted: Mon Jun 17, 2013 7:34 pm
by bn
Hi Max,
I usually do it as Klaus suggested. If you do it repeatly you can make your own command or do it in 1 line as shown in the example below.
There are two custom commands I made up to
set either the horizontal loc or the vertical loc or both
set just the vertical loc
or set the vertical loc inline
set the vertical loc in 1 line
see the comments in the code
Code: Select all
on mouseUp
put the long ID of image 1 into tObject
setLoc tObject, empty, 70 -- set either horizontal or vertical or both positions of object
wait 1 second
setVertLoc tObject, 250 -- set only vertical position of object
wait 1 second
set the loc of tObject to (item 1 of the loc of tObject),350 -- set the vertical position of object in 1 line
end mouseUp
on setLoc pObject, pHorz, pVert -- set either horizontal or vertical or both positions of object
put the loc of pObject into tLoc
if pHorz <> "" then put pHorz into item 1 of tLoc
if pVert <> "" then put pVert into item 2 of tLoc
set the loc of pObject to tLoc
end setLoc
on setVertLoc pObject, pVert -- set only vertical position of object
put the loc of pObject into tLoc
if pVert <> "" then put pVert into item 2 of tLoc
set the loc of pObject to tLoc
end setVertLoc
Kind regards
Bernd
Re: Working with coordinates
Posted: Mon Jun 17, 2013 8:16 pm
by dunbarx
All sound advice.
But I think it is important that you see what went wrong with your statement. LiveCode is extremely conversational and flexible, and this frequently leads to problems. Even though your line seems to read correctly, it breaks some rules. These rules may not be clearly spelled out anywhere, and so your error is understandable.
The "loc" is a property of an object, and when being set must take the form of a point: integer,integer. It cannot be deconstructed when setting. So even though it seems like you ought to be able to change the value of the second item of that property, you cannot. Properties have to be set strictly as they are formatted.
Data in variables is wide open and accessible down to the character level. So like Klaus said, you have control over the second item in a variable, but not the second item in a reference to a property. You have to work that data a bit first, again, just as both Klaus and Bernd showed. On the other hand, note that you can: get item 2 of the loc of graphic "rectangle", because that does not force the engine to set the property value.
But your attempt makes sense as far as it goes, and shows a good understanding of how LC is constructed. A little practice and you are on your way past these details.
Craig Newman
Re: Working with coordinates
Posted: Tue Jun 18, 2013 9:25 am
by MaxV
Thank you Dunbarx.