Help with Control.lua Re: Rocket Launch

Place to get help with not working mods / modding interface.
Musical_tanks
Burner Inserter
Burner Inserter
Posts: 11
Joined: Sat May 27, 2017 9:19 pm
Contact:

Help with Control.lua Re: Rocket Launch

Post by Musical_tanks »

Hello i recently released a mod that adds new payloads for the rocket silo, I have run into a problem with the control.lua in that I can't disable the 'launched without rocket' message (https://i.imgur.com/kOuOFLi.jpg). (mod: https://mods.factorio.com/mod/expanded-rocket-payloads)

I have tried several different versions of code in an attempt to silence the message but I can't get anything to work. Could someone give me a hand?

Items and techs and entities I can figure out, scripting code not so much :/


Edit: Here is an example of what I currently have

Code: Select all

local function disable_no_satellite_launch_message()
    if remote.interfaces["silo-script"] then
        remote.call("silo-script", "set_show_launched_without_satellite", false)
    end
end
User avatar
DaveMcW
Smart Inserter
Smart Inserter
Posts: 3717
Joined: Tue May 13, 2014 11:06 am
Contact:

Re: Help with Control.lua Re: Rocket Launch

Post by DaveMcW »

silo_script, not silo-script.
Musical_tanks
Burner Inserter
Burner Inserter
Posts: 11
Joined: Sat May 27, 2017 9:19 pm
Contact:

Re: Help with Control.lua Re: Rocket Launch

Post by Musical_tanks »

changed to

Code: Select all

local function disable_no_satellite_launch_message()
    if remote.interfaces["silo_script"] then
        remote.call("silo_script", "set_show_launched_without_satellite", false)
    end
end
still not working for me :/
User avatar
DaveMcW
Smart Inserter
Smart Inserter
Posts: 3717
Joined: Tue May 13, 2014 11:06 am
Contact:

Re: Help with Control.lua Re: Rocket Launch

Post by DaveMcW »

You need to attach your function to a script event.

Code: Select all

local function disable_no_satellite_launch_message()
    if remote.interfaces["silo_script"] then
        remote.call("silo_script", "set_show_launched_without_satellite", false)
    end
end
script.on_init(disable_no_satellite_launch_message)
Musical_tanks
Burner Inserter
Burner Inserter
Posts: 11
Joined: Sat May 27, 2017 9:19 pm
Contact:

Re: Help with Control.lua Re: Rocket Launch

Post by Musical_tanks »

Still having problems, I have 1 save where there are no warning messages ever even if I reduce the enabled mods down to my own (i think some other mods disabled the messages). Then I have another older save I added my mod to and that is what I have been using as the control which gets the warning message regardless of what I do.

So as far as I can tell that last code didn't work. I am trying to set up a new sandbox save to test this stuff out in but that may take a couple hours.
User avatar
DaveMcW
Smart Inserter
Smart Inserter
Posts: 3717
Joined: Tue May 13, 2014 11:06 am
Contact:

Re: Help with Control.lua Re: Rocket Launch

Post by DaveMcW »

script.on_init() only runs once, so you would have to test it on a new or unmodded save.

You can use also use a bigger hammer:

Code: Select all

script.on_event(defines.events.on_tick, disable_no_satellite_launch_message)
Musical_tanks
Burner Inserter
Burner Inserter
Posts: 11
Joined: Sat May 27, 2017 9:19 pm
Contact:

Re: Help with Control.lua Re: Rocket Launch

Post by Musical_tanks »

Dang that still doesn't work for me

Here is what I have

Code: Select all

script.on_event(defines.events.on_tick, disable_no_satellite_launch_message)

local function disable_no_satellite_launch_message()
    if remote.interfaces["silo_script"] then
        remote.call("silo_script", "set_show_launched_without_satellite", false)
    end
end
Musical_tanks
Burner Inserter
Burner Inserter
Posts: 11
Joined: Sat May 27, 2017 9:19 pm
Contact:

Re: Help with Control.lua Re: Rocket Launch

Post by Musical_tanks »

Ok so I think I have managed to kill the message, here is what I did.

Code: Select all

script.on_event(defines.events.on_rocket_launched, function(event)
    local rocket = event.rocket
    if rocket.get_item_count("satellite") < 1 then
     remote.call("silo_script", "set_show_launched_without_satellite", false)
    end
end)

script.on_init(setup_remote_call)
script.on_configuration_changed(setup_remote_call)

  function setup_remote_call()
    remote.call(interface_name, "set_show_launched_without_satellite", false)
end

script.on_event(defines.events.on_research_finished, function(event)
    if event.research.name == 'improved-space-program-theory' then
        function setup_remote_call()
            remote.call(interface_name, "set_show_launched_without_satellite", false)
        end
    end
end)
So the top code is what first killed the warning message in my older save. The first test launch I did the message showed up but the second (and third and fourth) the message did not.

The bottom code I threw together as a a set of other circumstances to hopefully kill the warning message before the top code is necessary. This includes when: mod and game versions change, when new saves are created with the mod active and most importantly when the mod's first tech is researched which will probably be the main way the message is killed when people add the mod to their pre-existing saves.

I haven't been able to test the bottom code and see if it actively kills the message yet but the game hasn't thrown any errors up with that code so here is hoping they work.
User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5207
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: Help with Control.lua Re: Rocket Launch

Post by eradicator »

Musical_tanks wrote: Wed Sep 26, 2018 10:50 am Dang that still doesn't work for me

Here is what I have

Code: Select all

script.on_event(defines.events.on_tick, disable_no_satellite_launch_message)

local function disable_no_satellite_launch_message()
    if remote.interfaces["silo_script"] then
        remote.call("silo_script", "set_show_launched_without_satellite", false)
    end
end
You can't register a function before you define the function. During that first line the value of "disable_no_sattelite_launch_message" is nil. You need to put all the "script.on_event()" bits at the end of the file (or at least after defining the function they're supposed to register. Your second example does the same mistake with "setup_remote_call".
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.
Amarula
Filter Inserter
Filter Inserter
Posts: 546
Joined: Fri Apr 27, 2018 1:29 pm
Contact:

Re: Help with Control.lua Re: Rocket Launch

Post by Amarula »

eradicator wrote: Thu Sep 27, 2018 11:09 am [You can't register a function before you define the function. During that first line the value of "disable_no_sattelite_launch_message" is nil. You need to put all the "script.on_event()" bits at the end of the file (or at least after defining the function they're supposed to register. Your second example does the same mistake with "setup_remote_call".
Thank you! I've been coding (C, C++, Java) for a long time, but new to Lua and I hadn't caught this, so many thanks for this very clear explanation!
My own personal Factorio super-power - running out of power.
User avatar
DaveMcW
Smart Inserter
Smart Inserter
Posts: 3717
Joined: Tue May 13, 2014 11:06 am
Contact:

Re: Help with Control.lua Re: Rocket Launch

Post by DaveMcW »

eradicator wrote: Thu Sep 27, 2018 11:09 amYour second example does the same mistake with "setup_remote_call".
Actually the second example works, because global functions (not declared with "local") are created before the lua file is executed.
User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5207
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: Help with Control.lua Re: Rocket Launch

Post by eradicator »

DaveMcW wrote: Thu Sep 27, 2018 2:43 pm
eradicator wrote: Thu Sep 27, 2018 11:09 amYour second example does the same mistake with "setup_remote_call".
Actually the second example works, because global functions (not declared with "local") are created before the lua file is executed.
False. Maybe you're confusing this with reading global values from inside registered functions? The function itself must be defined before registering it as an event handler, and global/local does not change this. Try this example in control.lua, which will not do anything (:

Code: Select all

script.on_event(defines.events.on_player_changed_position,generic_test_function)
function generic_test_function ()
  game.print('tested!')
  end
But this works:

Code: Select all

function generic_test_function ()
  game.print('tested!')
  end
script.on_event(defines.events.on_player_changed_position,generic_test_function)
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.
Post Reply

Return to “Modding help”