Page 1 of 1

[Solved] LuaPlayer doesn't contain key map_view_settings

Posted: Sun Aug 16, 2020 10:41 pm
by ickputzdirwech
When I run the following comand

Code: Select all

/c game.player.map_view_settings.show_logistic_network = false
I always get this error:

Code: Select all

LuaPlayer doesn't contain key map_view_settings
But according to https://lua-api.factorio.com/latest/Lua ... w_settings it does. Is this a bug or am I just doing something wrong?

Re: LuaPlayer doesn't contain key map_view_settings

Posted: Mon Aug 17, 2020 1:19 am
by orzelek
You need to adhere to instructions in API:
Prepare a table that contains values you want changed and assign it to the map_view_settings variable.
Try to make a table with show_logistic_network = false and assing it to /c game.player.map_view_settings.

Re: LuaPlayer doesn't contain key map_view_settings

Posted: Mon Aug 17, 2020 7:14 am
by ickputzdirwech
orzelek wrote: Mon Aug 17, 2020 1:19 am Try to make a table with show_logistic_network = false and assing it to /c game.player.map_view_settings.
Thanks for the reply! But how do I do this exactly? I actually want this for a mod I am working on.

And why would that make a difference? I thought the problem is that "player" doesn't recognise "map_view_settings" and not that "map_view_settings" doesn't recognise "show_logistic_network".

I don't know much about lua or about scripting/programming in general. I figured everything out my self, so sorry for the silly questions.

Re: LuaPlayer doesn't contain key map_view_settings

Posted: Mon Aug 17, 2020 7:36 am
by Bilka
ickputzdirwech wrote: Mon Aug 17, 2020 7:14 am
orzelek wrote: Mon Aug 17, 2020 1:19 am Try to make a table with show_logistic_network = false and assing it to /c game.player.map_view_settings.
Thanks for the reply! But how do I do this exactly? I actually want this for a mod I am working on.

And why would that make a difference? I thought the problem is that "player" doesn't recognise "map_view_settings" and not that "map_view_settings" doesn't recognise "show_logistic_network".

I don't know much about lua or about scripting/programming in general. I figured everything out my self, so sorry for the silly questions.
It makes a difference because map_view_settings is "write-only". By doing game.player.map_view_settings.foo, you are trying to get the game.player.map_view_settings table and index it with foo. But you cannot get game.player.map_view_settings since it is write-only (=not-readable), so you get the error.

By doing game.player.map_view_settings = {foo = true} you are not trying to read the table to index it, you simply assign something to it.

Maybe in simpler terms, this is similar:

Code: Select all

local bar = nil
bar.baz = "hello" -- tries to index bar as if it was a table but bar is nil, so this errors.
bar = {baz = "hello"} -- assigns a table to bar, doesn't care that bar is nil.

Re: LuaPlayer doesn't contain key map_view_settings

Posted: Mon Aug 17, 2020 2:50 pm
by ickputzdirwech
Thanks for the explanation! Now I understand it a bit better again. I still feel very stupid though because of what I picked up from you the following should work:

Code: Select all

/c game.player.map_view_settings = {show_logistic_network = false}
I fiddled with it for hours now and it doesn't crash like before, but it still doesn't toggle.

Maybe a bit context: I try to implement a shortcut, that toggles the debug setting "show-rail-signal-states". I assume this is a map_view_setting and thought maybe better I test it with a setting that is listed here first: https://lua-api.factorio.com/latest/Con ... ewSettings

Re: LuaPlayer doesn't contain key map_view_settings

Posted: Mon Aug 17, 2020 4:15 pm
by Bilka
You need "show-logistic-network" with dashes instead of underscores, see the docs.

Re: LuaPlayer doesn't contain key map_view_settings

Posted: Mon Aug 17, 2020 6:51 pm
by ickputzdirwech
Bilka wrote: Mon Aug 17, 2020 4:15 pm You need "show-logistic-network" with dashes instead of underscores, see the docs.

Code: Select all

/c game.player.map_view_settings = {show-logistic-network = false}
I tried that before (and at least 10 other variations) but it returns:

Code: Select all

'}' expected near '='

Re: LuaPlayer doesn't contain key map_view_settings

Posted: Mon Aug 17, 2020 6:56 pm
by Bilka
ickputzdirwech wrote: Mon Aug 17, 2020 6:51 pm
Bilka wrote: Mon Aug 17, 2020 4:15 pm You need "show-logistic-network" with dashes instead of underscores, see the docs.

Code: Select all

/c game.player.map_view_settings = {show-logistic-network = false}
I tried that before (and at least 10 other variations) but it returns:

Code: Select all

'}' expected near '='
Lua....

Code: Select all

/c game.player.map_view_settings = {["show-logistic-network"] = false}

Re: LuaPlayer doesn't contain key map_view_settings

Posted: Tue Aug 18, 2020 8:26 am
by ickputzdirwech
That works :) Thank you very much for your help and your patience!