# Introduction

This wiki page refers to a set of levels created for X-Moto about scripting and gives a more explained view of the scripts introducted in the levels. If you have any questions about the levels or this wiki, come to irc (IRC_tutorial) there is helpfull people almost always.

Levels:

The levels have a sophisticated script, by looking it you won't learn anything if you are a newbie. ;-)

Keys:

• H for help, usually re-generated when you go from a script to another
• Trainer: number keys told in the beginning

# #1 Blox

Level which tells you about block scripting. How to move and rotate blocks in various ways.

## 1. Teleporting a Block

no trainer key

To teleport the block from it's current location to another. Block must be dynamic!

Use function called:

```Game.SetBlockPos(block,x,y)
```

Parameters:

• block: a block id string like "block0" or "rect245". Block must be dynamic!
• x: position on the x-axis
• y: position on the y-axis

## 2. Moving a Block

Trainer key: 2

To move a block smoothly from it's current position to another (and back if you don't stop it).

Use function called:

```Game.SetDynamicBlockTranslation(block,fx,fy,period,startTime,endTime)
```

Parameters:

• block: a block id string like "block0" or "rect245". Block must be dynamic!
• fx: movement on the x-axis, position on level=blockx+fx
• fy: movement on the y-axis, position on level=blocky+fy
• period: how long it takes from the block to get to fx,fy and back.
• startTime: how long the moving waits before starting, milliseconds after function call
• endTime: how long the translation lasts. 0=infinite translation. if you want it only to go to fx,fy and not back then endTime=period/2

Other:

• You can combine different translations in favor of creating more complex translations.

## 3. Rotating a Block

Trainer key: 3

To rotate a block around an axel. Axel is defined with Game.SetBlockCenter() (#5. Setting The Block Center) function.

Use function called:

```Game.SetDynamicBlockSelfRotation(block, period, startTime, endTime)
```

Parameters:

• block: a block id string like "block0" or "rect245". Block must be dynamic!
• period: how long does the block rotate a 360
• startTime: how long the rotation waits before starting, milliseconds after function call
• endTime: how long the rotation lasts. 0=infinite rotation.

Example:

• If you want to do 2.5 loops where each loop takes 1000ms then period=1000 and endtime=1000*2.5

## 4. Stopping a Block

Trainer key: 4

To stop all block rotation and translation

Use function:

```Game.SetDynamicBlockNone(block)
```

Parameters:

• block: a block id string like "block0" or "rect245". Block must be dynamic!

## 5. Setting The Block Center

Trainer key: 5

To Set the Block's Center of rotation and positioning relative to the position on level.

Use function:

```Game.SetBlockCenter(block,x,y)
```

Parameters:

• block: a block id string like "block0" or "rect245". Block must be dynamic!
• x: position of the center on the x-axis
• y: position of the center on the y-axis

Other:

• Calculating the block center is hard(ish) so I prefer using this awesom tool by Deejay: X-Moto Tools

## 6. Set Block Rotation

Trainer key: 6

To set the block rotation to a specific angle. Remember Game.SetBlockCenter() (#5. Setting The Block Center) function.

Use function:

```Game.SetBlockRotation(block,a)
```

Parameters:

• block: a block id string like "block0" or "rect245". Block must be dynamic!
• angle: radians, the angle of the block (to use degrees: math.rad(degree value))

## 7. Move in Circles

Trainer key: 6

To make the block move in a circle of specific parameters. In this level I combined this function with a translation. (#2. Moving a Block)

Use function:

```Game.SetDynamicBlockRotation(block, initAngle, radius, period, startTime, endTime)
```

Parameters:

• block: a block id string like "block0" or "rect245". Block must be dynamic!
• initAngle: the point on the circle to start from
• radius: the size of the circle
• period: how long does the block rotate a 360
• startTime: how long the rotation waits before starting, milliseconds after function call
• endTime: how long the rotation lasts. 0=infinite rotation.

Other:

• To make the block rotate specific amount of loops then endTime=period*amount of loops ;-)