scenario scripts and areas

Place to get help with not working mods / modding interface.
Post Reply
User avatar
Watchinthegame
Manual Inserter
Manual Inserter
Posts: 3
Joined: Mon May 25, 2020 12:11 am
Contact:

scenario scripts and areas

Post 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?
Watchinthegame, havinabud... Factorio has me by the balls.

asdff45
Long Handed Inserter
Long Handed Inserter
Posts: 65
Joined: Sun Aug 07, 2016 1:23 pm
Contact:

Re: scenario scripts and areas

Post 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.
Last edited by asdff45 on Thu Jun 25, 2020 2:06 am, edited 1 time in total.

User avatar
Watchinthegame
Manual Inserter
Manual Inserter
Posts: 3
Joined: Mon May 25, 2020 12:11 am
Contact:

Re: scenario scripts and areas

Post by Watchinthegame »

Kinda intriguing to see these items in the editor and no-one seems to know why.
Watchinthegame, havinabud... Factorio has me by the balls.

User avatar
DaveMcW
Smart Inserter
Smart Inserter
Posts: 3707
Joined: Tue May 13, 2014 11:06 am
Contact:

Re: scenario scripts and areas

Post 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")

User avatar
Watchinthegame
Manual Inserter
Manual Inserter
Posts: 3
Joined: Mon May 25, 2020 12:11 am
Contact:

Re: scenario scripts and areas

Post 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.
Watchinthegame, havinabud... Factorio has me by the balls.

Post Reply

Return to “Modding help”