Page 1 of 1

[1.1.70] commands.add_command does nothing during script.on_load and script.on_init

Posted: Tue Nov 08, 2022 6:55 am
by ZwerOxotnik
Expected: Code:

Code: Select all

function add_commands()
	commands.add_command("test", 'test', function()
		game.print("test")
	end)
end

script.on_init(add_command)
script.on_load(add_command)
Steps to reproduce:
  • Download
    test_add_command.zip
    (465 Bytes) Downloaded 40 times
    and place it as scenario
  • Load "test_add_command" as a scenario
  • Try to type in /test in the chat
  • Save the game
  • Load the save
  • Try to type in /test in the chat
Actual Result:
  • There are no new commands after script.on_init and script.on_load
Notes:
  • I didn't check other Factorio versions

Re: [1.1.70] commands.add_command does nothing during script.on_load and script.on_init

Posted: Tue Nov 08, 2022 8:26 am
by Bilka
After fixing the typo in the script (add_commands in the last two lines) the command is registered as expected.

Re: [1.1.70] commands.add_command does nothing during script.on_load and script.on_init

Posted: Tue Nov 08, 2022 9:11 am
by ZwerOxotnik
You're right. However, I'm getting more and more confused.
30.985 Error ClientMultiplayerManager.cpp:1198: useful_book was registered for the following commands when the map was saved but has not re-registered them as a result of loading: candran and tl
30.985 Error ClientMultiplayerManager.cpp:99: MultiplayerManager failed: "" + multiplayer.script-command-mismatch + "
" + "
useful_book"
30.986 Info ClientMultiplayerManager.cpp:608: UpdateTick(14292533) changing state from(ConnectedLoadingMap) to(Failed)
For some reason, useful_book_0.20.3 doesn't add commands sometimes. I do the same actions and yet somehow I'm getting different results sometimes despite the same data. I don't know why and how. It did happen in singleplayer and in multiplayer. I'll publish logs as soon as I recheck it yet again with other people.

Re: [1.1.70] commands.add_command does nothing during script.on_load and script.on_init

Posted: Tue Nov 08, 2022 9:24 am
by ZwerOxotnik
This is mine, multiplayer (not re-registered the commands) -> singleplayer (fine) + saved -> loaded the save (fine)
factorio-current-ZwerOxotnik.log
(43.81 KiB) Downloaded 66 times

Re: [1.1.70] commands.add_command does nothing during script.on_load and script.on_init

Posted: Tue Nov 08, 2022 9:28 am
by ZwerOxotnik
Do clients check commands before script.on_load? The server saved the world and loaded it, and it works fine now.

Re: [1.1.70] commands.add_command does nothing during script.on_load and script.on_init

Posted: Tue Nov 08, 2022 9:45 am
by ZwerOxotnik
I need to check another thing, wait...

Re: [1.1.70] commands.add_command does nothing during script.on_load and script.on_init

Posted: Tue Nov 08, 2022 9:52 am
by ZwerOxotnik
Alright, I have no idea what had been happening. I'll let you know if the case will occur yet again.

Re: [1.1.70] commands.add_command does nothing during script.on_load and script.on_init

Posted: Tue Nov 08, 2022 10:08 am
by ZwerOxotnik
Never mind, it did happen, I'm kinda confused even more because I did the same action, and it worked fine in singleplayer.

1. That server disabled useful_book_0.20.3
2. Saved it
3. Loaded it
4. Saved it
5. Enabled useful_book_0.20.3
6. Loaded it
7. Other players can't join now because of the error
factorio-current-ZwerOxotnik2.log
(39.63 KiB) Downloaded 37 times

Re: [1.1.70] commands.add_command does nothing during script.on_load and script.on_init

Posted: Tue Nov 08, 2022 10:20 am
by ZwerOxotnik
Hm, it seems like something is wrong with useful_book's data, but I'm not sure how it happened. I'll recheck it again later.

Re: [1.1.70] commands.add_command does nothing during script.on_load and script.on_init

Posted: Tue Nov 08, 2022 10:51 am
by ZwerOxotnik
Never mind, the mod data were changed on on_configuration_changed event, but commands were added already. Case closed, probably.

Re: [1.1.70] commands.add_command does nothing during script.on_load and script.on_init

Posted: Tue Nov 08, 2022 11:09 am
by ZwerOxotnik
Why is it allowed to happen on_configuration_changed after on_init for the same mod?

Re: [1.1.70] commands.add_command does nothing during script.on_load and script.on_init

Posted: Tue Nov 08, 2022 12:33 pm
by FuryoftheStars
ZwerOxotnik wrote:
Tue Nov 08, 2022 11:09 am
Why is it allowed to happen on_configuration_changed after on_init for the same mod?
So that other mods can get the opportunity to make changes with the addition of your mod, if needed, I believe.

Re: [1.1.70] commands.add_command does nothing during script.on_load and script.on_init

Posted: Tue Nov 08, 2022 5:21 pm
by ZwerOxotnik
Sure, I mean this is a more specific case from the individual mod perspective, because the mod didn't change actually for itself since script.on_init happened for the mod already in the same situation. (I don't want to remove the data for other mods/scenarios)

Re: [1.1.70] commands.add_command does nothing during script.on_load and script.on_init

Posted: Tue Nov 08, 2022 5:29 pm
by FuryoftheStars
ZwerOxotnik wrote:
Tue Nov 08, 2022 5:21 pm
Sure, I mean this is a more specific case from the individual mod perspective, because the mod didn't change actually for itself since script.on_init happened for the mod already.
Yes, but most of the events don't fire for only one mod. on_init I think is one of the few that fires only for the mod that caused it.

on_configuration_changed, however, when it fires off, it does so for all mods.

Re: [1.1.70] commands.add_command does nothing during script.on_load and script.on_init

Posted: Tue Nov 08, 2022 5:41 pm
by ZwerOxotnik
Welp, I hope I understand it properly now, otherwise I'll write about it here again.