Are there any tutorials for making scenarios?

This is the place to share custom user maps, scenarios, and campaigns.
ATMunn
Inserter
Inserter
Posts: 37
Joined: Thu Jan 12, 2017 2:22 am
Contact:

Are there any tutorials for making scenarios?

Post by ATMunn »

Hello fellow Factorians!
For a little bit now I've been interested in creating scenarios for Factorio. I understand the map editor and how to use it, but all that seems to allow is essentially glorified Freeplay maps. I would like to know if there is somewhere where I can find a tutorial on actually scripting a scenario. I have a basic understanding of programming, I'm not super familiar with Lua though. (although it seems like a very simple language)

Thanks. :)
User avatar
Adil
Filter Inserter
Filter Inserter
Posts: 945
Joined: Fri Aug 15, 2014 8:36 pm
Contact:

Re: Are there any tutorials for making scenarios?

Post by Adil »

Well, creating scenario is not different from performing any other act of modding. So you'd actually need the tutorial to scripting in factorio.

Each scenario has its own control.lua file, which is executed when the scenario is loaded and it is that file that performs all the magic differentiating your scenario from the freeplay.

In default campaigns or scenarios are actually using the dev's written lua libraries (factorio/data/core/lualib). So, in the control.lua devs only initialize their library and register library's function as a handler to all possible events.
You may try to use parts of their code from default scenarios, those cover most of the possible situations.
You don't have to write your script in the same pattern as they do if you want.

Also, I myself don't do factorio scenarios, as there's much of other stuff of greater priority that I must\should\want do, but if you come up with prepared map and drawn out plot, I may help you translate that into lua.
I do mods. Modding wiki is friend, it teaches how to mod. Api docs is friend too...
I also update mods, some of them even work.
Recently I did a mod tutorial.
ATMunn
Inserter
Inserter
Posts: 37
Joined: Thu Jan 12, 2017 2:22 am
Contact:

Re: Are there any tutorials for making scenarios?

Post by ATMunn »

Okay, I see. I have tried a couple times with doing normal mods, however the tutorial on the wiki isn't up to date and I haven't found anything else that is. I might come up with a simple little map and make it in the editor, you can help me make that in Lua and I can examine the code from there and figure out what does what and hopefully be able to go from there.

Sidenote: Are there any up-to-date tutorials out there for mods? It's really something I'm interested in, but it gets kind of frustrating having tutorials that tell you things that only half work, you know what I mean?
User avatar
LotA
Fast Inserter
Fast Inserter
Posts: 117
Joined: Fri Oct 10, 2014 11:41 am
Contact:

Re: Are there any tutorials for making scenarios?

Post by LotA »

The only available tutorial that I know of is this one. (I actually didn't watched it)

This is for mods, a scenario has a few more restrictions : you can't edit the data.raw. Basicaly : you cannot "create/define" new entities, you can only use and modify the existing ones.
If you know a bit about programming, all you're gotta need is the api documentation
Best way to get information is to check any lua files from the factorio directory (base files or mod files)

What I can say about making a scenario :
- you're "access point" to the game logic is via event handlers : for instance you can generate client's UIs in the "on_player_joined_game" then use "on_gui_clicked" (and then checks which button triggered the event) for more advanced UI interactions.
- Any variables that needs to be stored (and shared among peers) shall be put in the global table : for instance, if you use a custom, variable list of whatever, you'll need to store this list as global.my_list_name
- Avoid as much as possible the use of on_tick event as it's triggered 60 times a sec (at least move away any heavy code from there) but
- You'll need the on_tick event whenever you need a clock or a timer
- If you ever need to copy-paste parts of your map, then you'd better "script it out" using LuaSurface:create_entity/LuaSurface:set_tiles/etc because the map editor is very limited and you'll get more power doing "everything" through scripts (checks how supply-challenge generate its spawns... or even how RSO modifies the map resources)
User avatar
DRY411S
Filter Inserter
Filter Inserter
Posts: 731
Joined: Sun Mar 13, 2016 9:48 am
Contact:

Re: Are there any tutorials for making scenarios?

Post by DRY411S »

Dragging this up after so long to ask 2 related questions.

If I create a scenario packaged as a mod, so that it has code that alters data.raw AND a scenarios folder, does the data stage code run, or does the game see the scenarios folder in the mod, and ignore the data stage stuff?

If I disable the mod, does it disable the scenario?
Post Reply

Return to “Maps and Scenarios”