Reading file by lua

Place to get help with not working mods / modding interface.
Post Reply
craftoBot
Inserter
Inserter
Posts: 37
Joined: Sun Dec 28, 2014 7:39 pm
Contact:

Reading file by lua

Post by craftoBot »

I need to read file contents by lua
file was in directory script-output
and contains text

Choumiko
Smart Inserter
Smart Inserter
Posts: 1352
Joined: Fri Mar 21, 2014 10:51 pm
Contact:

Re: Reading file by lua

Post by Choumiko »

That's not possible.
You can work around it though, at least in single player. Have your mod write to the file via serpent.dump to let's say output.lua
Create a symlink or the Linux equivalent in your mod folder pointing to output.lua
Now you can do something like: variable = require "output" in control.lua
Each time you update/rewrite the file you need to reload the game for the changes to be read.
Quite hacky :D

craftoBot
Inserter
Inserter
Posts: 37
Joined: Sun Dec 28, 2014 7:39 pm
Contact:

Re: Reading file by lua

Post by craftoBot »

It's it's unbelivable...
WHY I CAN"T JUST READ FILE?! FACTORIO, WHY YOUR LUA IS SO STRANGE!!!
WHYYYY>>>>
Okay...
Let's try to hack it like this, so this is strange.....

ratchetfreak
Filter Inserter
Filter Inserter
Posts: 952
Joined: Sat May 23, 2015 12:10 pm
Contact:

Re: Reading file by lua

Post by ratchetfreak »

craftoBot wrote:It's it's unbelivable...
WHY I CAN"T JUST READ FILE?! FACTORIO, WHY YOUR LUA IS SO STRANGE!!!
WHYYYY>>>>
Okay...
Let's try to hack it like this, so this is strange.....
because desyncs

factorio relies on each mod doing the exact same thing on each client

arbitrary files don't allow that

jorgenRe
Filter Inserter
Filter Inserter
Posts: 535
Joined: Wed Apr 09, 2014 3:32 pm
Contact:

Re: Reading file by lua

Post by jorgenRe »

craftoBot wrote:It's it's unbelivable...
WHY I CAN"T JUST READ FILE?! FACTORIO, WHY YOUR LUA IS SO STRANGE!!!
WHYYYY>>>>
Okay...
Let's try to hack it like this, so this is strange.....
Wow wow relax. I don't think it even is neccecary to read/write files because what is in global tables stays there no matter how many times you restart Factorio. And I think that'd way easier too ;)!

Edit i take that back :lol: !
I'm now working on my The Underground mod and i wanted to just write down the entity names and their position relevant to the others in a file...
Last edited by jorgenRe on Wed Aug 12, 2015 5:58 pm, edited 1 time in total.
Logo
Noticed the told change in FFF #111 so il continue to use my signature ^_^
Thanks for listening to our suggestions, devs :D!
I would jump of joy if we could specify which tiles spawned in a surfaces

craftoBot
Inserter
Inserter
Posts: 37
Joined: Sun Dec 28, 2014 7:39 pm
Contact:

Re: Reading file by lua

Post by craftoBot »

ratchetfreak wrote:
craftoBot wrote:It's it's unbelivable...
WHY I CAN"T JUST READ FILE?! FACTORIO, WHY YOUR LUA IS SO STRANGE!!!
WHYYYY>>>>
Okay...
Let's try to hack it like this, so this is strange.....
because desyncs

factorio relies on each mod doing the exact same thing on each client

arbitrary files don't allow that

I can check for file existance, i need only to read file content to send it into sync tables.....
It's strange that standart io.* package of lua is removed

craftoBot
Inserter
Inserter
Posts: 37
Joined: Sun Dec 28, 2014 7:39 pm
Contact:

Re: Reading file by lua

Post by craftoBot »

jorgenRe wrote:
craftoBot wrote:It's it's unbelivable...
WHY I CAN"T JUST READ FILE?! FACTORIO, WHY YOUR LUA IS SO STRANGE!!!
WHYYYY>>>>
Okay...
Let's try to hack it like this, so this is strange.....
Wow wow relax. I don't think it even is neccecary to read/write files because what is in global tables stays there no matter how many times you restart Factorio. And I think that'd way easier too ;)!
I know, and i just need to export file from factorio to use by another program e.g texteditor and then import edited file back to game

ratchetfreak
Filter Inserter
Filter Inserter
Posts: 952
Joined: Sat May 23, 2015 12:10 pm
Contact:

Re: Reading file by lua

Post by ratchetfreak »

craftoBot wrote: I know, and i just need to export file from factorio to use by another program e.g texteditor and then import edited file back to game
then put the result data in a lua file that the mod imports

craftoBot
Inserter
Inserter
Posts: 37
Joined: Sun Dec 28, 2014 7:39 pm
Contact:

Re: Reading file by lua

Post by craftoBot »

ratchetfreak wrote:
craftoBot wrote: I know, and i just need to export file from factorio to use by another program e.g texteditor and then import edited file back to game
then put the result data in a lua file that the mod imports
I already understand, but i want this data in plain text, not lua, but i will do like this....

sebgggg
Burner Inserter
Burner Inserter
Posts: 15
Joined: Tue Aug 09, 2016 6:57 am
Contact:

Re: Reading file by lua

Post by sebgggg »

Choumiko wrote:That's not possible.
You can work around it though, at least in single player. Have your mod write to the file via serpent.dump to let's say output.lua
Create a symlink or the Linux equivalent in your mod folder pointing to output.lua
Now you can do something like: variable = require "output" in control.lua
Each time you update/rewrite the file you need to reload the game for the changes to be read.
Quite hacky :D
OMFG! I'm ashamed i did not think of that... For my defense, i play on Windows, on which you can do the same with an admin command line:
mklink link target

_Peter_
Inserter
Inserter
Posts: 23
Joined: Wed Aug 17, 2016 7:50 pm
Contact:

Re: Reading file by lua

Post by _Peter_ »

ratchetfreak wrote:
craftoBot wrote:It's it's unbelivable...
WHY I CAN"T JUST READ FILE?! FACTORIO, WHY YOUR LUA IS SO STRANGE!!!
WHYYYY>>>>
Okay...
Let's try to hack it like this, so this is strange.....
because desyncs

factorio relies on each mod doing the exact same thing on each client

arbitrary files don't allow that
I think I understand the desync problem, but what if I want to make a mod that works only in single player? Then it would be perfectly ok to change the mod behavior from outside, or not?

I think it should be left to the discretion of the mod programmer whether or not to use methods that would not work in multiplayer, that means whether or not to read from files.

_Peter_
Inserter
Inserter
Posts: 23
Joined: Wed Aug 17, 2016 7:50 pm
Contact:

Re: Reading file by lua

Post by _Peter_ »

I was planning to write a mod that cannot do things that the player cannot do, in essence a voice interface for playing Factorio, including some natural language understanding parts.

This should not cause any desyncs, but of course it would require to get some streaming data from the outside into a mod.

Has such a type of mod be considered (and maybe ruled out for certain reasons)?

User avatar
DaveMcW
Smart Inserter
Smart Inserter
Posts: 3700
Joined: Tue May 13, 2014 11:06 am
Contact:

Re: Reading file by lua

Post by DaveMcW »

Since 2015, the devs have added RCON support to the headless server. This allows arbitrary input while keeping multiplayer compatibility.

User avatar
ownlyme
Filter Inserter
Filter Inserter
Posts: 400
Joined: Thu Dec 21, 2017 8:02 am
Contact:

Re: Reading file by lua

Post by ownlyme »

cant you just use this require hack with different filenames?
edit: works only on start
Screenshot_1.png
Screenshot_1.png (59.72 KiB) Viewed 4181 times
mods.factorio.com/user/ownlyme
My requests: uiAbove||Grenade arc||Blueprint allies||Creeps forget command/ don't get removed||Player Modifiers||textbox::selection||Better Heat IF||Singleplayer RCON||tank bug w/ min_range >= projectile_creation_distance

Post Reply

Return to “Modding help”