Page 1 of 1

scenario scripts and areas

Posted: Wed Jun 24, 2020 11:29 pm
by Watchinthegame
Hello, Factorio has successsfully turned me into a stump.

Making a scenario, I would like to automate some scripts upon launch and upon player entering an area.
Entering code into the Script area during scenario editing, seems to do nothing. So too are the areas (doing nothing).

I kinda trust that these will be documented somewhere and will eventually do something when v1.0 is launched.

Am I missing something?

Re: scenario scripts and areas

Posted: Thu Jun 25, 2020 12:38 am
by asdff45
As far as i understand it: An scenario is an advanced mod. For scripts, to run, you have to create a control.lua file and in there you can program whatever you want to do.

Wikipage about Scenarios: https://wiki.factorio.com/Scenario_system

The `control.lua` Events, your interested in:
Startup scripts:
on_load: https://lua-api.factorio.com/latest/Lua ... ap.on_load
on_init: https://lua-api.factorio.com/latest/Lua ... ap.on_init

I misread you. You want to do something, when a player is entering an area. I dont think that is directly possible :(
But i am not sure.

Re: scenario scripts and areas

Posted: Thu Jun 25, 2020 1:38 am
by Watchinthegame
Kinda intriguing to see these items in the editor and no-one seems to know why.

Re: scenario scripts and areas

Posted: Thu Jun 25, 2020 2:09 am
by DaveMcW
How to use Lua Snippets

1. Map editor -> Tools -> Areas and positions -> Run Lua Snippets
2. Change the snippet to "Example", or type your own. The special variable "area" describes the area to run the snippet on.
3. Use your mouse to select an area on the map. The code is immediately run on the area you selected. Example Video.


How to use Areas

1. Map editor -> Tools -> Areas and positions -> Areas
2. Use your mouse to select an area on the map.
3. In control.lua access the area you selected using this code:

Code: Select all

local area = game.get_surface("nauvis").get_script_area("1")

How to use Positions

1. Map editor -> Tools -> Areas and positions -> Cursor
2. Use your mouse to select a position on the map.
3. In control.lua access the position you selected using this code:

Code: Select all

local position = game.get_surface("nauvis").get_script_position("1")

Re: scenario scripts and areas

Posted: Sat Sep 25, 2021 9:37 pm
by Watchinthegame
Am I not able to have a script to research all tech in that script tool?
I wanted all tech to be researched automatically for my custom scenario.

/c game.player.force.research_all_technologies()

pasting that in the snippet with a label, doesn't launch at scenario play start.

This is what I am assuming I could do with that script tool, maybe it's not for that.