Difference between revisions of "Posn"

From AGI Wiki
Jump to navigationJump to search
(Created page with "The '''posn''' test command returns TRUE if the screen coordinates of the screen object's bottom left pixel are within a specified region. == Syntax == posn(screen obj...")
 
 
(4 intermediate revisions by the same user not shown)
Line 11: Line 11:
 
The position test commands ('''posn''', '''[[center.posn]]''', '''[[right.posn]]''', and '''[[obj.in.box]]''' are used to determine if a screen object's position is within a certain area.
 
The position test commands ('''posn''', '''[[center.posn]]''', '''[[right.posn]]''', and '''[[obj.in.box]]''' are used to determine if a screen object's position is within a certain area.
  
The reference point for the '''posn''' command is the left pixel of the [[screen object]]'s baseline, which is also the object's screen position. Sometimes a programmer needs to test for positions relative to the center or right edge of the object. This could be done by using the '''posn''' command and the screen object's width and performing some additional mathematical commands. Thankfully, Sierra included the additional position test commands to make it easier to check for these conditions.
+
The reference point for the '''posn''' command is the left pixel of [[screen object]] '''oA''''s baseline (bottom row of the current [[cel]]), which is also the object's screen position.
  
The region to be tested is bounded by ('''X1''', '''Y1''') - ('''X2''', '''Y2'''). The test returns TRUE if the reference point of [[screen object]] '''oA''' is >= '''X1''' AND <= '''X2''' AND >= '''Y1''' AND <= '''Y2'''.
+
The region to be tested is bounded by ('''X1''', '''Y1''') - ('''X2''', '''Y2'''). The test returns TRUE if the reference point is >= '''X1''' AND <= '''X2''' AND >= '''Y1''' AND <= '''Y2'''.
 +
 
 +
Sometimes a programmer needs to test for positions relative to the center or right edge of the object. This could be done by using the '''posn''' command and the screen object's width and performing some additional mathematical commands. Thankfully, Sierra included the additional position test commands to make it easier to check for these conditions.
  
 
This test command can be combined with the <code>NOT</code> operator to test if an object is NOT in a specified region.
 
This test command can be combined with the <code>NOT</code> operator to test if an object is NOT in a specified region.
Line 19: Line 21:
 
== Possible Errors ==
 
== Possible Errors ==
  
AGI expects the coordinates to be in upper-left to lower-right format. '''X1''' ''must' be less than or equal to '''X2''' and '''Y1''' ''must'' be less than or equal to '''Y2''', or the test will always fail.
+
AGI does not check that object number '''oA''' is a valid [[screen object]]. If it is not, the '''posn''' command will access invalid memory and the result of the test will be meaningless.
 +
 
 +
AGI expects the coordinates to be in upper-left to lower-right format. '''X1''' ''must'' be less than or equal to '''X2''' and '''Y1''' ''must'' be less than or equal to '''Y2''', or the test will always fail.
  
 
== Example ==
 
== Example ==
Line 47: Line 51:
 
'''[[obj.in.box]]'''<br />
 
'''[[obj.in.box]]'''<br />
 
'''[[right.posn]]'''<br />
 
'''[[right.posn]]'''<br />
[Category:Commands]<br />
+
[[Category:Commands]]<br />

Latest revision as of 10:35, 20 April 2019

The posn test command returns TRUE if the screen coordinates of the screen object's bottom left pixel are within a specified region.

Syntax

posn(obj oA, byt X1, byt Y1, byt X2, byt Y2)

Remarks

Test commands are only valid in an if statement.

The position test commands (posn, center.posn, right.posn, and obj.in.box are used to determine if a screen object's position is within a certain area.

The reference point for the posn command is the left pixel of screen object oA's baseline (bottom row of the current cel), which is also the object's screen position.

The region to be tested is bounded by (X1, Y1) - (X2, Y2). The test returns TRUE if the reference point is >= X1 AND <= X2 AND >= Y1 AND <= Y2.

Sometimes a programmer needs to test for positions relative to the center or right edge of the object. This could be done by using the posn command and the screen object's width and performing some additional mathematical commands. Thankfully, Sierra included the additional position test commands to make it easier to check for these conditions.

This test command can be combined with the NOT operator to test if an object is NOT in a specified region.

Possible Errors

AGI does not check that object number oA is a valid screen object. If it is not, the posn command will access invalid memory and the result of the test will be meaningless.

AGI expects the coordinates to be in upper-left to lower-right format. X1 must be less than or equal to X2 and Y1 must be less than or equal to Y2, or the test will always fail.

Example

Code:

<syntaxhighlight lang="agi"> if(posn(o1, 0, 120, 60, 130))

 { 
 print("the object's lower left corner is in the box");
 }

</syntaxhighlight>

Technical Information

Required Interpreter Version: Available in all AGI versions.
Byte-Code Value: 11 (0x0B hex)

See Also

Test Commands
center.posn
obj.in.box
right.posn