[Solved] How do I get the name of the current scenario?

Place to get help with not working mods / modding interface.
Post Reply
User avatar
QGamer
Fast Inserter
Fast Inserter
Posts: 213
Joined: Fri Apr 14, 2017 9:27 pm
Contact:

[Solved] How do I get the name of the current scenario?

Post by QGamer »

Hello,
I want to access the name of the current scenario from within control.lua. How does one go about doing that? I can't seem to find anything in LuaGameScript that allows me to access this property.

If it helps, I'm trying to print a message to the console, but only in a very specific scenario that is included in one of my other mods:

Code: Select all

if get_scenario_name() == "my-scenario-from-another-mod" then
	player.print( "special message" )
end
Last edited by QGamer on Wed May 26, 2021 8:12 pm, edited 1 time in total.
"Adam fell that men might be; and men are, that they might have joy."

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

Re: How do I get the name of the current scenario?

Post by DaveMcW »

You can define a unique remote interface.

in scenario:

Code: Select all

remote.add_interface("my_scenario", {})
in mod:

Code: Select all

if remote.interfaces["my_scenario"] then
  game.print("special message")
end
Last edited by DaveMcW on Wed May 26, 2021 6:32 pm, edited 1 time in total.

Bilka
Factorio Staff
Factorio Staff
Posts: 3123
Joined: Sat Aug 13, 2016 9:20 am
Contact:

Re: How do I get the name of the current scenario?

Post by Bilka »

I'm an admin over at https://wiki.factorio.com. Feel free to contact me if there's anything wrong (or right) with it.

User avatar
QGamer
Fast Inserter
Fast Inserter
Posts: 213
Joined: Fri Apr 14, 2017 9:27 pm
Contact:

Re: How do I get the name of the current scenario?

Post by QGamer »

Bilka wrote:
Wed May 26, 2021 6:31 pm
https://lua-api.factorio.com/latest/Lua ... trap.level should help.
This was exactly what I was looking for.
Thank you so much!
"Adam fell that men might be; and men are, that they might have joy."

Post Reply

Return to “Modding help”