data['title']); if($title_nice != "Main Page") { echo "

"; echo $title_nice; echo "

"; } ?>

Contents

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:

Levels ReadMe

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 ;-)

Notes

  • All blocks that are moved must be in main layer, if you have 2 main layers you must use the original one, otherwise X-Moto will segfault (=crash).

#2 Events

Level which teaches you how to get actions happening, messages printed at right places etc.

1. OnLoad()

Function OnLoad is called by X-Moto when the level is loaded. allowing you to start initial animations and print a welcome message. In this level it does loads of things:

function OnLoad()
	--add msgs to a list which is later parsed to give time to read the msgs
	msgs={"Hello, and welcome to LTS 2. 'H' for detailed help!","Tonight you are going to learn...","how to use script functions provided by X-Moto. [OnLoad]","See the wiki doc  associated with these levels!",""}
	timer=200 --interval between msgs (changeable)
	ticks=100
	--other gfx
	Game.SetDynamicBlockTranslation("wave1",-3,0,1500,0,0)
	--help
	Game.SetKeyHook("H","Helpp")
	--explain system
	Game.SetKeyHook("E","Explain")
	expl={"function OnLoad()",'Game.Message("Hello, and welcome")...',"return true", "end","First we define the function.","Then we call the X-Moto's message function.",  "Lastly we return true (needed in OnLoad) and end the function.",""} 
	oexpl=expl
	return true
end

First we define the function so that X-Moto can call it. Then we add messages for the player to my amazing message system. after that we make the waves move under the bridge. then we setup the Help and the Explain keys. But this could be simply done just like this:

function OnLoad()
       Game.Message("Welcome, press 'H' for help!")
	--other gfx
	Game.SetDynamicBlockTranslation("wave1",-3,0,1500,0,0)
	--help
	Game.SetKeyHook("H","Helpp")
	return true
end

Before ending OnLoad we must call return true, otherwise it will crash X-Moto.

2. Zone.OnEnter()

The OnEnter function, which X-Moto calls when player enter a specific zone, takes a zone id. The zone must be defined! for example my zone id is z1={}. I define all my zones in the beginning of the script.

function z1.OnEnter()
	if explaining==false then
		Game.ClearMessages()
		ClearMsgs(0)
		Game.Message("Ah, you entered the bridge! [Zone.OnEnter()]")
		expl={"function z1.OnEnter()",'Game.Message("Ah, you entered the bridge!  ...")',"end","First we define the function,","then we call X-Moto's message function,","and lastly we end the function.",""};oexpl=expl 
	end
end

First we define the function so that X-Moto can call it. Then we Clear messages, print info to player and setup new explanation to my awesome explanation system which the player can see.

3. Zone.OnLeave()

The OnLeave function, which X-Moto calls when player leaves a specific zone, takes a zone id. The zone must be defined! for example my zone id is z1={}. I define all my zones in the beginning of the script.

function z1.OnLeave()
	if explaining==false then
		Game.ClearMessages()
		ClearMsgs(0)
		Game.Message(""And now you left the bridge! [Zone.OnLeave()]"")
		expl={"function z1.OnEnter()",'Game.Message("And now you left the bridge!  ...")',"end","First we define the function,","then we call X-Moto's message function,","and lastly we end the function.",""};oexpl=expl 
	end
end

First we define the function so that X-Moto can call it. Then we Clear messages, print info to player and setup new explanation to my awesome explanation system which the player can see.

4. Entity.Touch()

Note: it is not OnTouch, X-Moto functions are sometimes confusingly differently named. The Touch function, which X-Moto calls when player touches an entity, takes an entity id. The entity must be defined! for example my entity is flower={}. I define all my entities in the beginning of the script.

function flower.Touch()
	Game.ClearMessages()
	Game.Message("You crapped the beautiful flower... [Entity.Touch()]")
	expl={"function flower.Touch()",'Game.Message("You crapped the beautiful flower...")',"end","First we define the function,","then we call X-Moto's message  function,","and lastly we end the function.",""};oexpl=expl
	ClearMsgs(140)
	msgs={"You feel dizzy.","event",0}
	Game.KillEntity("flower")
end

First we define the function so that X-Moto can call it. Then we clear messages and give one. Then we update the explain and message system again. Lastly we delete the flower.

5. OnWheel1Touchs()

The function is called by X-Moto when the player's wheel touches/leaves the ground.

function OnWheel1Touchs(bStatus)
	if spikesa==1 and bStatus==1 then
		spikesa=0
		Game.SetDynamicBlockTranslation("spikes1",0,-6,50,0,25)
	end
end

First we define the function. Then we see if the bStatus is 1. bStatus is 1 on touch and 0 on leave. Then we drop the spikes with SetDynamicBlockTranslation see #2. Moving a Block.

6. OnSomerSault()

The function is called by X-Moto when the player makes a somersault.

function OnSomersault(bClockWise)
	if summer==1 then
		saults=saults+1
		if saults==5 then
			Game.Message("Almost there 5 to go!")
		end
		if saults==10 then
			ClearMsgs(250)
			ticks=250
			msgs={"You are free now, I go to bed.","event",4}
		end
	end
end

First we define the function, the bClockWise is 1 if the somersault is clockwise if it is counterclockwise then it is 0. Then we see if we are at the end, where the somersaults are calculated, the somersaults you made before are not counted. Then we add saults by 1. Lastly we see if you have done some saults and action accordingly.

Credits

Me Tuhoojabotti, I made all the levels ;-)

oskari and Cigam has gave me some ideas I've used.


This page was last modified on 26 November 2010, at 11:22. This page has been accessed 11,892 times.

  

Copyright © 2006