Page 1 of 1
Are there any tutorials for making scenarios?
Posted: Sun Jan 15, 2017 4:49 pm
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.
Re: Are there any tutorials for making scenarios?
Posted: Sun Jan 15, 2017 6:46 pm
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.
Re: Are there any tutorials for making scenarios?
Posted: Sun Jan 15, 2017 9:07 pm
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?
Re: Are there any tutorials for making scenarios?
Posted: Sun Jan 22, 2017 1:56 pm
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)
Re: Are there any tutorials for making scenarios?
Posted: Fri Mar 20, 2020 1:00 pm
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?