[Solved] LuaPlayer doesn't contain key map_view_settings

Place to get help with not working mods / modding interface.
User avatar
ickputzdirwech
Filter Inserter
Filter Inserter
Posts: 799
Joined: Sun May 07, 2017 10:16 am
Contact:

[Solved] LuaPlayer doesn't contain key map_view_settings

Post 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?
Last edited by ickputzdirwech on Tue Aug 18, 2020 8:27 am, edited 2 times in total.
Mods: Shortcuts for 1.1, ick's Sea Block, ick's vanilla tweaks
Tools: Atom language pack
Text quickly seems cold and unfriendly. Be careful how you write and interpret what others have written.
- A reminder for me and all who read what I write
orzelek
Smart Inserter
Smart Inserter
Posts: 3928
Joined: Fri Apr 03, 2015 10:20 am
Contact:

Re: LuaPlayer doesn't contain key map_view_settings

Post 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.
User avatar
ickputzdirwech
Filter Inserter
Filter Inserter
Posts: 799
Joined: Sun May 07, 2017 10:16 am
Contact:

Re: LuaPlayer doesn't contain key map_view_settings

Post 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.
Mods: Shortcuts for 1.1, ick's Sea Block, ick's vanilla tweaks
Tools: Atom language pack
Text quickly seems cold and unfriendly. Be careful how you write and interpret what others have written.
- A reminder for me and all who read what I write
Bilka
Factorio Staff
Factorio Staff
Posts: 3455
Joined: Sat Aug 13, 2016 9:20 am
Contact:

Re: LuaPlayer doesn't contain key map_view_settings

Post 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.
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
ickputzdirwech
Filter Inserter
Filter Inserter
Posts: 799
Joined: Sun May 07, 2017 10:16 am
Contact:

Re: LuaPlayer doesn't contain key map_view_settings

Post 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
Last edited by ickputzdirwech on Mon Aug 17, 2020 4:37 pm, edited 2 times in total.
Mods: Shortcuts for 1.1, ick's Sea Block, ick's vanilla tweaks
Tools: Atom language pack
Text quickly seems cold and unfriendly. Be careful how you write and interpret what others have written.
- A reminder for me and all who read what I write
Bilka
Factorio Staff
Factorio Staff
Posts: 3455
Joined: Sat Aug 13, 2016 9:20 am
Contact:

Re: LuaPlayer doesn't contain key map_view_settings

Post by Bilka »

You need "show-logistic-network" with dashes instead of underscores, see the docs.
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
ickputzdirwech
Filter Inserter
Filter Inserter
Posts: 799
Joined: Sun May 07, 2017 10:16 am
Contact:

Re: LuaPlayer doesn't contain key map_view_settings

Post 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 '='
Mods: Shortcuts for 1.1, ick's Sea Block, ick's vanilla tweaks
Tools: Atom language pack
Text quickly seems cold and unfriendly. Be careful how you write and interpret what others have written.
- A reminder for me and all who read what I write
Bilka
Factorio Staff
Factorio Staff
Posts: 3455
Joined: Sat Aug 13, 2016 9:20 am
Contact:

Re: LuaPlayer doesn't contain key map_view_settings

Post 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}
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
ickputzdirwech
Filter Inserter
Filter Inserter
Posts: 799
Joined: Sun May 07, 2017 10:16 am
Contact:

Re: LuaPlayer doesn't contain key map_view_settings

Post by ickputzdirwech »

That works :) Thank you very much for your help and your patience!
Mods: Shortcuts for 1.1, ick's Sea Block, ick's vanilla tweaks
Tools: Atom language pack
Text quickly seems cold and unfriendly. Be careful how you write and interpret what others have written.
- A reminder for me and all who read what I write
Post Reply

Return to “Modding help”