Page 1 of 1

[0.17.69] Can assign values to LuaRemote and possibly others

Posted: Sun Sep 29, 2019 5:43 pm
by Boodals
I just found that you can assign variables to LuaRemote and possibly others.

Code: Select all

/c remote.potato = 4 --no error
/c game.print(remote.potato) --prints 4

Re: [0.17.69] Can assign values to LuaRemote and possibly others

Posted: Sun Sep 29, 2019 8:04 pm
by Klonan
So what does this break?

Re: [0.17.69] Can assign values to LuaRemote and possibly others

Posted: Sun Sep 29, 2019 9:01 pm
by Boodals
Klonan wrote:
Sun Sep 29, 2019 8:04 pm
So what does this break?
The rule that you cant modify LuaObjects other than their explicit properties? idk
You could ask the opposite question about LuaObjects that don't allow setting random variables.

Re: [0.17.69] Can assign values to LuaRemote and possibly others

Posted: Sun Sep 29, 2019 11:48 pm
by Rseding91
Thanks for the report however there's no such rule; It's just "how it is." There are infrequently (if ever) rules/guidelines for anything in Factorio. Most everything is just "what ever the programmer thought sounded good on the day he wrote it". Back when Kovarex or Tomas started the Lua API they made it so trying to write to properties on LuaObjects that didn't exist threw an error instead of silently doing nothing. So, that's what it still does today.

Nobody ever explained why or thought that maybe another method would be better (silently doing nothing?) - everything just silently uses the same code that was written years ago.

Some of the Lua API has been implemented differently over the years as it needed to work differently than the basic "read/write values for a single lua context" and so diverged and didn't implement the same "error if someone tries to write when this doesn't support writing".

I don't consider it worth going over all of the Lua API and making it a rule that everything needs to follow this pattern because it's not going to add any value in the end and it's just going to generate more bug reports about other places where it might be missing, more commits to work on, more code, and in the end nothing will be different.

I would rather focus our collective efforts on things which actually improve the game: fixing crashes, fixing desycs, improving game performance, making new mods possible by adding new things to the mod API and so on.