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

Bugs that are actually features.
User avatar
ZwerOxotnik
Fast Inserter
Fast Inserter
Posts: 115
Joined: Tue Dec 19, 2017 6:58 pm
Contact:

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

Post 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 62 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
Bilka
Factorio Staff
Factorio Staff
Posts: 3310
Joined: Sat Aug 13, 2016 9:20 am
Contact:

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

Post by Bilka »

After fixing the typo in the script (add_commands in the last two lines) the command is registered as expected.
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
ZwerOxotnik
Fast Inserter
Fast Inserter
Posts: 115
Joined: Tue Dec 19, 2017 6:58 pm
Contact:

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

Post 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.
User avatar
ZwerOxotnik
Fast Inserter
Fast Inserter
Posts: 115
Joined: Tue Dec 19, 2017 6:58 pm
Contact:

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

Post 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 87 times
User avatar
ZwerOxotnik
Fast Inserter
Fast Inserter
Posts: 115
Joined: Tue Dec 19, 2017 6:58 pm
Contact:

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

Post by ZwerOxotnik »

Do clients check commands before script.on_load? The server saved the world and loaded it, and it works fine now.
User avatar
ZwerOxotnik
Fast Inserter
Fast Inserter
Posts: 115
Joined: Tue Dec 19, 2017 6:58 pm
Contact:

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

Post by ZwerOxotnik »

I need to check another thing, wait...
User avatar
ZwerOxotnik
Fast Inserter
Fast Inserter
Posts: 115
Joined: Tue Dec 19, 2017 6:58 pm
Contact:

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

Post by ZwerOxotnik »

Alright, I have no idea what had been happening. I'll let you know if the case will occur yet again.
Last edited by ZwerOxotnik on Tue Nov 08, 2022 10:08 am, edited 1 time in total.
User avatar
ZwerOxotnik
Fast Inserter
Fast Inserter
Posts: 115
Joined: Tue Dec 19, 2017 6:58 pm
Contact:

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

Post 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 55 times
User avatar
ZwerOxotnik
Fast Inserter
Fast Inserter
Posts: 115
Joined: Tue Dec 19, 2017 6:58 pm
Contact:

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

Post 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.
User avatar
ZwerOxotnik
Fast Inserter
Fast Inserter
Posts: 115
Joined: Tue Dec 19, 2017 6:58 pm
Contact:

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

Post by ZwerOxotnik »

Never mind, the mod data were changed on on_configuration_changed event, but commands were added already. Case closed, probably.
User avatar
ZwerOxotnik
Fast Inserter
Fast Inserter
Posts: 115
Joined: Tue Dec 19, 2017 6:58 pm
Contact:

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

Post by ZwerOxotnik »

Why is it allowed to happen on_configuration_changed after on_init for the same mod?
FuryoftheStars
Smart Inserter
Smart Inserter
Posts: 2768
Joined: Tue Apr 25, 2017 2:01 pm
Contact:

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

Post 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.
My Mods: Classic Factorio Basic Oil Processing | Sulfur Production from Oils | Wood to Oil Processing | Infinite Resources - Normal Yield | Tree Saplings (Redux) | Alien Biomes Tweaked | Restrictions on Artificial Tiles | New Gear Girl & HR Graphics
User avatar
ZwerOxotnik
Fast Inserter
Fast Inserter
Posts: 115
Joined: Tue Dec 19, 2017 6:58 pm
Contact:

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

Post 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)
FuryoftheStars
Smart Inserter
Smart Inserter
Posts: 2768
Joined: Tue Apr 25, 2017 2:01 pm
Contact:

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

Post 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.
My Mods: Classic Factorio Basic Oil Processing | Sulfur Production from Oils | Wood to Oil Processing | Infinite Resources - Normal Yield | Tree Saplings (Redux) | Alien Biomes Tweaked | Restrictions on Artificial Tiles | New Gear Girl & HR Graphics
User avatar
ZwerOxotnik
Fast Inserter
Fast Inserter
Posts: 115
Joined: Tue Dec 19, 2017 6:58 pm
Contact:

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

Post by ZwerOxotnik »

Welp, I hope I understand it properly now, otherwise I'll write about it here again.
Post Reply

Return to “Not a bug”