Getting started
Last modification: 455 days, 12 hours ago
This article will explain how to create your first scripted map and the lifecycle of scripts that will normally be put into Script tiles on a map.
You may want to get familiar with the architecture of the game to better understand where the game finds and how it loads Lua scripts.
Before we begin, make sure to prepare your game for modifications - this will enable developer mode and map editor for you.
Making your first map
- Run the modified game (double click
C:/I2Mod/infinitode-2.exeor run it through the terminal) - Click on the
New gamebutton, you will see a couple of default maps used for development purposes - Click on a thumbnail of any map to open its regular menu. You will find a couple of new buttons in the upper right corner of the leve's menu:
purple tools will open the Level configuration editor and
blue pencil with paper will open the map editor for the selected level - Open the
configuration editor and then click on Add level. Name your new map, for exampletest_map, confirm the name and hitSaveMap name should be at least 2 characters long, use a-z0-9 and underscores
- Go back to the main menu and return to the list of levels, your new empty map should appear on the list
Now you can select the map from the list of levels and open the
map editor.
Editing the map should be familiar for you, but this new editor has a couple of differences compared to the regular editor of custom maps:
- Max size of the map is limited to 32x32
- Tiles won't be removed from the map if you don't have them in your inventory1
- Map will be saved into
levels/mapsfolder and not into your save file. You will find your map as a(your map name).jsonfile inside this folder
You can create any kind of map and play on it. Keep reading to know how to make things more fun.
Adding scripts to your map
Follow these steps to add scripts to your map:
- Open map editor of your new map
- Add some roads, at least one Portal and Base tile to make your map playable. Remember that you can create any tile you need with the developer mode
- Open item creation menu (see dev mode usage page if you don't know how to do that), select
TILEitem type. In theTile typedropdown menu, selectSCRIPTand click on theGivebutton - new empty Script tile will be added to your inventoryIDfield is an unique identifier of your tile. If you want to create multiple different Script tiles, make sure their IDs are different. You can click on the
reload button to generate new unique ID - Find the newly created Script tile in the
Specialtab of map editor and place it on any free space of your map - Select the Script tile on your map - you will find the large
Source codefield in its menu. You can write Lua code there2 or copy it from your favorite text editor - use regularCtrl+C / Ctrl+Vkeystroke orCopy / Pastebuttons below the source code field. Paste this code into the Source code field:log("Hello world!) - Hit
Savebutton to save your code into the tile. Now each time you start playing on this map, your code will be executed - Start your map by pressing the
Playbutton / returning to the list of levels and playing it in a regular way. You should find theScript: Hello world!message in the terminal, which means your code has been successfully executed
You can place any amount of different Script tiles on your map - they will be executed in the same Lua environment in left-right, bottom-top order.
Further reading
- Get familiar with Lua scripting language
- Read about the structure and lifecycle of Lua scripts inside the Script tiles
- Learn more about the architecture of the game
-
Pro tip: you are in a developer mode now, feel free to create any kind of tiles you need - they will be added to your inventory and will appear in the map editor ↩
-
Pro tip: there's a small triangle button on the left side of the
Source codefield, use it to enlarge the field horizontally ↩