Changes between Version 2 and Version 3 of code/Scripting
- Timestamp:
- Apr 10, 2008, 4:33:42 PM (17 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
code/Scripting
v2 v3 12 12 If your using the special lua tags ''<?lua'' and ''?>'' you can create levels easier. You could use loops to generate more objects and you can let a level depend on earlier accomplishments of the player. If you use random parameters you can even create a level which looks slightly different every time a player plays it. Here some examples how you could use Lua in our level files. 13 13 14 === Asteroid field ===14 === Example: Asteroid field === 15 15 As I write this wiki page we have a level with 226 asteroids in it. For each asteroid we need one line of XML code: 16 16 {{{ … … 24 24 With the scripting engine we could generate those asteroids a lot easier: 25 25 {{{ 26 ... (has to be tested first) 26 <?lua 27 for i = 1, 226, 1 28 do ?> 29 <Model position="<?lua print(math.random(-19597, 18732))?>, 30 <?lua print(math.random(-19597, 18732)) ?>, 31 <?lua print(math.random(-19597, 18732)) ?>" scale="<?lua print(math.random( 20, 119)) ?>" 32 mesh="ast<?lua print(i%6 + 1) ?>.mesh" rotationAxis="<?lua print(math.random()) ?>, 33 <?lua print(math.random()) ?>, <?lua print(math.random()) ?> 34 " rotationRate="<?lua print(math.random(16, 44)) ?>" /> 35 <?lua 36 end 37 ?> 27 38 }}} 39 This will randomly arrange asteroids of different look and rotation axis and speed in an area. In fact you can code any Lua you want according to the [http://www.lua.org/manual/5.1/manual.htm Lua-Manual]. To actually add something to the XML-output you can use the ''print'' function. The above example shows you best how this works.