-
Notifications
You must be signed in to change notification settings - Fork 1
Lua Workshops
Below you can find some really great tutorials by Adngel for Lua and TombEngine (TEN).
The first we are going to do, is modify our gameflow
script to can include our new level (or the many levels that we want).
What are these Lua files?
In the TombIDE program, you can find your Lua files by pressing the third button on the left panel:
In your Scripts folder, you will find these files, they are part of the Ten system. (You need them, you can edit them, but not delete them).
- Settings: This contains some options about error logs, and some movements conditions, (in development).
- Gameflow: This is like your main script file, here you will add your new levels, and their object data.
- Strings: This is the place where you can set your new text lines.
- Util: This is a code that contains some functions to make scripting easier.
- Timer: This is a module with tools to make timed actions.
- EventSequence: This module includes the EvenSequence structure to schedule a series of actions. (in development).
Apart from these ones, then there are some extra Lua files dedicated to each level, for example, you have their Title.lua
and TestLevel.lua
.
To add a new level, you must do three things:
- Create a new level block in the Gameflow.lua.
- Create a new string for your level name.
- Create a new lua file for that level.
The script may look complex at first sight, but if you take a more general look, you can see that there are some 3 areas in this script.
- Header, is the area that initialize system data, you usually don’t need to touch this.
- Title level also need its block, and this is its place.
- Level blocks, in this pic it’s shown 1 level block, but you may add as many level blocks as levels has your game.
So you can add your next level block at the end of the list. The level block has this minimal structure:
**Level1** = Level.new()
Level1.nameKey = "L0_Title"
Level1.scriptFile = "Scripts\\l_LaraGym.lua"
Level1.ambientTrack = "108"
Level1.levelFile = "Data\\LaraGym.ten"
Level1.loadScreenFile = "Screens\\rome.jpg"
Flow.AddLevel (level1)
Please not that "Level1" as above must be unique for each level, I think an easy way to do that is just calling Level1 the first level, Level2 the second, etc..
Completing the level block:
- nameKey Is the name of your level, you must add it to your strings file and put it here.
- scriptFile Here is where you will put you Lua level file, we will cover it later.
- ambientTrack This is the ambient music that has your level at the begginng, you can find the songs in the folder Engine/Audio
- levelFile This is the file of your level, located in the Engine/Data folder.
- loadScreenFile This is the image that will appear while your level is loading, you can find and add pictures in the folder Engine/Screens
The strings go in your String.lua file, so open it and go at the end of the file.
Before the bracket close, that's the place to inject your new strings. You can just copy the structure of the previous string and paste it below.
Pay attention to the commas, only the last string don’t need comma at the end, but the rest yes need a comma after the bracket like: },
- In the string, the string var (variable) name need to be unique, I’m using L0_Title, L1_Title, L2_Title, etc..
- Inside, there are many gaps, it’s designed so each one will be used for different languages, at the moment we are going to fill only the first one that is used for English.
- Once you’ve got it, save the strings.lua, and write in the nameKey of your level block, the string var name, between double commas. So in my case, L0_title
In TombIDE, you can add a new file by pressing the left button of the mouse, on File Explorer, there you can find the create a new file.
In the new window, just put the name of your new file, and choose the Lua format. Then press Create.
When you create a new file, this file will be empty, to have a minimal workable level code, you need to add the next lines:
-- FILE: \Levels\l_laraGym.lua
LevelFuncs.OnLoad = function() end
LevelFuncs.OnSave = function() end
LevelFuncs.OnStart = function() end
LevelFuncs.OnControlPhase = function() end
LevelFuncs.OnEnd = function() end
Put this code in the file you've just created and save it.
Finally, you can update the **scriptFile ** value in your level block with the address to your lua file. (In my case: "Scripts\l_LaraGym.lua")
Once you've done, you should be able to find your level in the game menu and play it, (although first you must have compiled the Tomb Editor level!)
If it fails, the first check should be the log document. (you will find it in Engine\Logs), look for a line that says [error], usually at the end of the document, these logs tend to provide useful information, like the line where your script has failed. (It can be for the lack of a comma, for a misspelled word, etc...)
That provided code, was quite minimal, there are more elements that you can add to your level block, like horizon, sky layer, fog, weather, etc... You can find all the features in the documentation. (You can download from this git hub: https://github.com/Stranger1992/Tomb-Engine-Demo-Levels )
For example:
Level0 = Level.new()
Level0.nameKey = "l0_Title"
Level0.scriptFile = "Scripts\\Levels\\l_LaraGym.lua"
Level0.ambientTrack = "108"
Level0.levelFile = "Data\\LaraMoves.ten"
Level0.loadScreenFile = "Screens\\rome.jpg"
Level0.horizon = true
Level0.weather = 2
Level0.weatherStrength = 1
Level0.layer1 = Flow.SkyLayer.new(Color.new(72, 80, 96), 5)
Level0.fog = Flow.Fog.new(Color.new(32, 56, 64), 5, 20)
Flow.AddLevel(Level0)