Page 1 of 1

Help with Control.lua Re: Rocket Launch

Posted: Tue Sep 25, 2018 9:52 pm
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

Re: Help with Control.lua Re: Rocket Launch

Posted: Tue Sep 25, 2018 10:47 pm
by DaveMcW
silo_script, not silo-script.

Re: Help with Control.lua Re: Rocket Launch

Posted: Tue Sep 25, 2018 11:34 pm
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 :/

Re: Help with Control.lua Re: Rocket Launch

Posted: Wed Sep 26, 2018 12:04 am
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)

Re: Help with Control.lua Re: Rocket Launch

Posted: Wed Sep 26, 2018 1:05 am
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.

Re: Help with Control.lua Re: Rocket Launch

Posted: Wed Sep 26, 2018 1:12 am
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)

Re: Help with Control.lua Re: Rocket Launch

Posted: Wed Sep 26, 2018 10:50 am
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

Re: Help with Control.lua Re: Rocket Launch

Posted: Wed Sep 26, 2018 11:43 pm
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.

Re: Help with Control.lua Re: Rocket Launch

Posted: Thu Sep 27, 2018 11:09 am
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".

Re: Help with Control.lua Re: Rocket Launch

Posted: Thu Sep 27, 2018 2:12 pm
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!

Re: Help with Control.lua Re: Rocket Launch

Posted: Thu Sep 27, 2018 2:43 pm
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.

Re: Help with Control.lua Re: Rocket Launch

Posted: Thu Sep 27, 2018 4:58 pm
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)