Latest Posts

Changes in WikiSandbox

Revision Differences of Revision 74

Test [[ wikisyntax | wiki syntax ]] here :-) ¶

Some initial help for creating a campaign. What you should know before reading on: ¶

* [Fir
st steps for a scenario]( ¶
* Make sure to use a plain text editor when writing scripts ¶

### init.lua ¶

You ha
ve read that the file `scripting/init.lua` is the main entry for your scenario. So this file is the starting point and should contain necessary global settings. This file contains usually different parts:

#### Including global fnctionality ¶

~~~~ ¶
include "
scripting/coroutine.lua" ¶
include "scripting/messages.lua" ¶
include "scripting/ui.lua" ¶
~~~~ ¶

The files which get included here
contain functions which you may need in your project. E.g. the file `coroutine.lua` contain a function `sleep(time)`. Those files (and their functions) are described in [Auxiliary Scripts]( Please take a look at the includes above and look into the documentation to get knowledge about their possibilities. Don't worry if you don't understand that much at the moment. Later on we will see how to use them. ¶

#### Global
variables ¶

In this pa
rt of the `init.lua` we define variables which we want to be available each time, in each other file. That's why they are called 'global' variables. This global variables are shortcuts and prevent writing each time the same: ¶

~~~~ ¶
plr = wl.Game().players[1] ¶
map = wl.Game().map ¶
plr_sf = map.player_slots[1].starting_field ¶
~~~~ ¶

The meaning of the variables: ¶

* `plr = wl.Game().players[1]`: This reads the first defined player of the map and assign it to the variable 'plr'. You have to set the player(s) in the map editor to get this to work. ¶
* `map = wl.Game().map`: The variable 'map' gives you now access to many properties of the map itself, e.g. to the function `get_field()` in [Map]( This will be the most used function in your scenario. ¶
* `plr_sf = map.player_slots[1].starting_field`: You have set a player in the map editor on a field, so this assigns this field to the global variable 'plr_sf' ¶

#### Other files ¶

Now we are ready with initialization and can work on to get the story alive. To split of initialization and other stuff, the last line in our `init.lua` contains another include: ¶

~~~~ ¶
include "map:scripting/story_script.lua" ¶
~~~~ ¶

The file `story_script.lua` contains the main thread for our scenario. The include at the end of the `init.lua` makes sure all other initialization is done and all defined variables are available in each further included file . ¶

### story_script.lua ¶

In this file we create our scenario and add conditions and objectives a player has to fulfill. ¶

The map you have created is empty by default. You have set a player, but no buildings at all. This is the first thing we should consider: ¶

#### Place buildings ¶

First we place the headquarters for the player 1. Do you remember you have set the global variables `plr` and `plr_sf`? Here we use them: ¶

~~~~ ¶
hq = plr:place_building("empire_headquarters", plr_sf, false, true) ¶
~~~~ ¶

We call the function place_building() with the needed arguments (the entries in the brackets). Note the colon between `plr` and the functions name. Now its time for a first test. Run: ¶

~~~~ ¶
./widelands --scenario=/full/path/to/the/map.wmf ¶
~~~~ ¶

You should see the placed headquarters after loading is complete. ¶