Syntax

Opens a block where \property calls the catalogue command <Family><Property> on one object, so its id and the family name are written once.

WITH <FAMILY> <expression>
  \<property> [<arguments>]
  … \<property> …
ENDWITH
END WITH

Also written : WITH SPRITE

Parts

<FAMILY>A word that starts catalogue command names: SPRITE, TEXT, OBJECT, CAMERA, PARTICLES, IMAGE, MUSIC, MEMBLOCK…
<expression>The object id passed as first argument: a variable, ships[3], a number such as 1.
<property>The end of the command name: \position with SPRITE calls SpritePosition().
<arguments>The other arguments of a write, separated by commas, without parentheses.

Good to know

  • The place decides the meaning. At the head of a statement, \prop writes: \x 50 is SpriteX(s, 50). Anywhere else it reads: x# = \x is SpriteX(s).
  • A write has no =. \x = 50 is not refused, but the program it produces fails to start.
  • A write must start the statement. In IF … THEN \visible 1, the \visible is read as a read and the program fails to start. Use a block IF, as in the example.
  • A property the catalogue does not have is a compile error: "Unknown property in WITH SPRITE: \positon".
  • Lines that do not start with \ are ordinary statements. No nesting: a WITH inside a WITH is refused.
  • AGK names such as SetSpritePosition or GetSpriteX do not exist: the object comes first, the property second, without Set or Get.

Example

s = CreateSprite(0)WITH SPRITE s  \position 100, 200  \size 64, 64  \x 50  x# = \x  IF \visible = 0    \visible 1  ENDIFENDWITHConsole(Str(x#) + " " + Str(SpriteY(s)))   ' 50 200
In the manual : Shorthands