x (Game Maker)

## x

x - the x-location of an object in a room.

## Description

horizontal location
- @-- X --@ +

x is an object's x-location or horizontal location. In 2D, the x-location is counted in pixels. Even though x can contain a number with a decimal fraction (i.e. 5.2), it will only take into consideration the whole part of the number.

You can subtract from or add to x to move an instance left or right.

## Examples

### Example of Use

x contains the horizontal location of an object in relation to the current room and never the view. If you wanted to put an object 50 pixels from the left side of a room, you could use the below code.

````x = 50;`
```

### Moving Left or Right

You can subtract from or add to x to move an instance left or right. Subtracting from or adding a negative number will move it left.

``````x = x - 1; // move one pixel to the left
x = x + -2; // move two pixels to the left```
```

Adding a positive number to x will move an instance right.

````x = x + 1; //move one pixel to the right`
```

### Random x-location

````x = random(room_width);`
```

## Similar To

page revision: 20, last edited: 30 Jun 2012 15:43