Comunicating data.lua and control.lua
Comunicating data.lua and control.lua
How can I comunicate the data.lua and the control.lua?
Also, can I use the file io to write in a file inside the mod folder? If so, how can I get the path?
Also, can I use the file io to write in a file inside the mod folder? If so, how can I get the path?
Re: Comunicating data.lua and control.lua
how do you mean communicate? make it so that your mod does not load if the base mod is not first? If so I imagine you could use some form of io.read in data.lua to check if base is the first one if not then to add it first and remove it from further down (it's in the form of a table if you haven't noticed lol). I'll test and then edit but...ficolas wrote:How can I comunicate the data.lua and the control.lua?
Also, can I use the file io to write in a file inside the mod folder? If so, how can I get the path?
as to writing a file to the mod folder I've used f=io.open("filename.ext", "w") or a+ instead of w for append, and then you can just use f:write(print("whatever you want to show up in the file")) then close the file when you are finished with f:close() as to the path I'm almost sure that if you use the commands from the data/control.lua it create the file within the same location (though it might put it in the same place as running them from console which is where the factorio executable is factorio\bin\x64 for me, if it does create it in the bin folder then just use ../../mods/mod-name/file-name.ext to save it where you want it)
edit1: io.open from data.lua creates the file in the bin folder so.. you'll have to use ../.. to get to the mods folder
<I'm really not active any more so these may not be up to date>
~FreeER=Factorio Modding
- Factorio Wiki
- My Factorio Modding Guide
- Wiki Modding Guide
Feel free to pm me![Smile :)](./images/smilies/icon_e_smile.gif)
Or drop into #factorio on irc.esper.net
~FreeER=Factorio Modding
- Factorio Wiki
- My Factorio Modding Guide
- Wiki Modding Guide
Feel free to pm me
![Smile :)](./images/smilies/icon_e_smile.gif)
Or drop into #factorio on irc.esper.net
Re: Comunicating data.lua and control.lua
../../mods/F-mod?
Re: Comunicating data.lua and control.lua
yes for example
(I did this in console but it should work in data.lua or any other lua file actually)
f=io.open("../../mods/F-mod/f-mod.txt", "w") --remember case sensitivity
f:write(print("this is a test"))
f:close()
now go read the file![Smile :)](./images/smilies/icon_e_smile.gif)
I got f=io.open("../../mods/mod-list.json", "w")
modlist = f:read("*a")
f:close()
to store the mod-list.json file into modlist but as to a good way to check if base is first idk lol
should be easy enough to resave it to the file
(I did this in console but it should work in data.lua or any other lua file actually)
f=io.open("../../mods/F-mod/f-mod.txt", "w") --remember case sensitivity
f:write(print("this is a test"))
f:close()
now go read the file
![Smile :)](./images/smilies/icon_e_smile.gif)
I got f=io.open("../../mods/mod-list.json", "w")
modlist = f:read("*a")
f:close()
to store the mod-list.json file into modlist but as to a good way to check if base is first idk lol
should be easy enough to resave it to the file
<I'm really not active any more so these may not be up to date>
~FreeER=Factorio Modding
- Factorio Wiki
- My Factorio Modding Guide
- Wiki Modding Guide
Feel free to pm me![Smile :)](./images/smilies/icon_e_smile.gif)
Or drop into #factorio on irc.esper.net
~FreeER=Factorio Modding
- Factorio Wiki
- My Factorio Modding Guide
- Wiki Modding Guide
Feel free to pm me
![Smile :)](./images/smilies/icon_e_smile.gif)
Or drop into #factorio on irc.esper.net
Re: Comunicating data.lua and control.lua
A tiny bit of testing, emphasis on tiny about to leave for my next class
, and this might be able to work for checking mod-list.json (until it gets fixed in the next update lol)
I think the main issue would be the comma at the end of the basecheck string because if base is the last entry then the , would not exist and it might cause issues lol
I'm sure there is a better way (prettier even) but this is what I came up with in that time frame lol
![Sad :(](./images/smilies/icon_e_sad.gif)
Code: Select all
f=io.open("../../mods/mod-list.json")
modlist = f:read("*a")
basecheck=[[{
"mods":
[
{
"name": "base",
"enabled": "true"
},]]
if string.sub(modlist, 0, 104) ~= basecheck then
string.gsub(modlist, [[{
"name": "base",
"enabled": "true"
},]], "")
modlist=string.sub(modlist,0,23)..[[{
"name": "base",
"enabled": "true"
},]]..string.sub(modlist,24)
f:write(print(modlist))
end
f:close()
I'm sure there is a better way (prettier even) but this is what I came up with in that time frame lol
<I'm really not active any more so these may not be up to date>
~FreeER=Factorio Modding
- Factorio Wiki
- My Factorio Modding Guide
- Wiki Modding Guide
Feel free to pm me![Smile :)](./images/smilies/icon_e_smile.gif)
Or drop into #factorio on irc.esper.net
~FreeER=Factorio Modding
- Factorio Wiki
- My Factorio Modding Guide
- Wiki Modding Guide
Feel free to pm me
![Smile :)](./images/smilies/icon_e_smile.gif)
Or drop into #factorio on irc.esper.net
Re: Comunicating data.lua and control.lua
This is nice temporary solution (if it works), but we will disable i/o operations in the lua in the future as this is huge security hole.
P.S. Tomas just made the mod dependencies, so they will be available from 0.4.
P.S. Tomas just made the mod dependencies, so they will be available from 0.4.
Re: Comunicating data.lua and control.lua
:S so how will I make my scoreboard for the rocket gamemode?kovarex wrote:This is nice temporary solution (if it works), but we will disable i/o operations in the lua in the future as this is huge security hole.
P.S. Tomas just made the mod dependencies, so they will be available from 0.4.
Re: Comunicating data.lua and control.lua
yeah, I was kind of assuming you would do that eventually
If any of the modders had wanted to be mean they could have used factorio to launch a format script lol. os.execute probably needs to be removed as well. Though you could perhaps allow io operations within the individual mod directory just not outside of it maybe, to allow for logfiles or whatever lol. I was actually looking into creating a mod that would guide people through creating a mod (and create examples using io), but I can't seem to find a good way to delay the messages so... back to the original plan
![Smile :)](./images/smilies/icon_e_smile.gif)
<I'm really not active any more so these may not be up to date>
~FreeER=Factorio Modding
- Factorio Wiki
- My Factorio Modding Guide
- Wiki Modding Guide
Feel free to pm me![Smile :)](./images/smilies/icon_e_smile.gif)
Or drop into #factorio on irc.esper.net
~FreeER=Factorio Modding
- Factorio Wiki
- My Factorio Modding Guide
- Wiki Modding Guide
Feel free to pm me
![Smile :)](./images/smilies/icon_e_smile.gif)
Or drop into #factorio on irc.esper.net
Re: Comunicating data.lua and control.lua
how will it react if mod is not found. Can I have optional dependencies?kovarex wrote:This is nice temporary solution (if it works), but we will disable i/o operations in the lua in the future as this is huge security hole.
P.S. Tomas just made the mod dependencies, so they will be available from 0.4.
Test mode
Searching Flashlight
[WIP]Fluid handling expansion
[WIP]PvP gamescript
[WIP]Rocket Express
Autofill: The torch has been pass to Nexela
Searching Flashlight
[WIP]Fluid handling expansion
[WIP]PvP gamescript
[WIP]Rocket Express
Autofill: The torch has been pass to Nexela
Re: Comunicating data.lua and control.lua
Yes.rk84 wrote:Can I have optional dependencies?
You can also specify condition of the mod version you depend on ... more info in the 0.4 update.
Re: Comunicating data.lua and control.lua
The changes will be as follows:rk84 wrote:how will it react if mod is not found. Can I have optional dependencies?kovarex wrote:This is nice temporary solution (if it works), but we will disable i/o operations in the lua in the future as this is huge security hole.
P.S. Tomas just made the mod dependencies, so they will be available from 0.4.
1) Mod can have dependencies on other mods
2) Dependency can be vague (name of other mod) or parametrized by the version (= < > <= >=)
3) Dependencies can be optional (dependency will be checked only if the other mod is enabled and has valid dependencies)
4) Mods ordering will be specified primarily by the dependencies and secondarily by the name
Custom ordering will not be possible anymore (would cause issues with replay, multiplayer, etc.)
Re: Comunicating data.lua and control.lua
Sounds great!
But what is about "not optional" dependencies? I think about (optional) mod-addons. I think I should use an example to point it out more clearly.
I.e. I move the fertilizer-production-line into an optional addon for the treefarm-mod. Obviously the addon needs the "root" treefarm-mod.
What will happen if the user forgot to install the treefarm-mod? Maybe it is not a common scenario, but a possible imo.
But what is about "not optional" dependencies? I think about (optional) mod-addons. I think I should use an example to point it out more clearly.
I.e. I move the fertilizer-production-line into an optional addon for the treefarm-mod. Obviously the addon needs the "root" treefarm-mod.
What will happen if the user forgot to install the treefarm-mod? Maybe it is not a common scenario, but a possible imo.
Re: Comunicating data.lua and control.lua
In this case the game starts normally, however the dependency for the addon is not satisfied (the treefarm-mod is missing). Therefore the addon mod is marked as not valid (will be red in the mods gui) and is not used in the game.
Basically we added a new mod state "valid". So now the mod can be enabled / disabled (user setting) and valid / invalid (some dependency missing or dependency version not satisfied or dependency not valid or dependency not enabled). Only valid enabled mods are used for the game.
There are small changes in the mod manager gui related to this as well:
Mods that are not valid are marked with red color (as opposed to disabled mods now).
Mods that are not enabled are grey.
Mods always have the same ordering (independent of the valid / enabled setting).
Dependencies are displayed and dependencies causing invalidity are marked with red (so the user can see what is wrong).
Basically we added a new mod state "valid". So now the mod can be enabled / disabled (user setting) and valid / invalid (some dependency missing or dependency version not satisfied or dependency not valid or dependency not enabled). Only valid enabled mods are used for the game.
There are small changes in the mod manager gui related to this as well:
Mods that are not valid are marked with red color (as opposed to disabled mods now).
Mods that are not enabled are grey.
Mods always have the same ordering (independent of the valid / enabled setting).
Dependencies are displayed and dependencies causing invalidity are marked with red (so the user can see what is wrong).
Re: Comunicating data.lua and control.lua
Well-wrought idea! (But honestly I did not expect anything else from you guys
)
![Wink ;)](./images/smilies/icon_e_wink.gif)
-
- Filter Inserter
- Posts: 559
- Joined: Mon Mar 04, 2013 9:23 am
- Contact:
Re: Comunicating data.lua and control.lua
If you do so please provide your own function which will encapsulate the low level I/O functionality so that modders could still read or write certain data in their files. Doung this you could esily limit where theese files can bee.kovarex wrote:This is nice temporary solution (if it works), but we will disable i/o operations in the lua in the future as this is huge security hole.
P.S. Tomas just made the mod dependencies, so they will be available from 0.4.
Re: Comunicating data.lua and control.lua
This is problematic. The game must be deterministic, always. When you are replaying game, everything that changes the game state must be the same the second time. That is the reason why the script shouldn't be able to access anything that could act differently when you replay the game (IO/Network/non-deterministic random number generator etc), this will be especially important in the network game.SilverWarior wrote:If you do so please provide your own function which will encapsulate the low level I/O functionality so that modders could still read or write certain data in their files. Doung this you could esily limit where theese files can bee.kovarex wrote:This is nice temporary solution (if it works), but we will disable i/o operations in the lua in the future as this is huge security hole.
P.S. Tomas just made the mod dependencies, so they will be available from 0.4.
What is the reason for the mod to write/read files anyway?
Re: Comunicating data.lua and control.lua
For example, Im making a new gamemode where you need to build a rocket to scape the planet, and I want to make a highscore board, but I cant without io or sonething :Skovarex wrote:This is problematic. The game must be deterministic, always. When you are replaying game, everything that changes the game state must be the same the second time. That is the reason why the script shouldn't be able to access anything that could act differently when you replay the game (IO/Network/non-deterministic random number generator etc), this will be especially important in the network game.SilverWarior wrote:If you do so please provide your own function which will encapsulate the low level I/O functionality so that modders could still read or write certain data in their files. Doung this you could esily limit where theese files can bee.kovarex wrote:This is nice temporary solution (if it works), but we will disable i/o operations in the lua in the future as this is huge security hole.
P.S. Tomas just made the mod dependencies, so they will be available from 0.4.
What is the reason for the mod to write/read files anyway?
Re: Comunicating data.lua and control.lua
Could player-data.json have place for mods to write/read (via methods) scores and achievements?
Test mode
Searching Flashlight
[WIP]Fluid handling expansion
[WIP]PvP gamescript
[WIP]Rocket Express
Autofill: The torch has been pass to Nexela
Searching Flashlight
[WIP]Fluid handling expansion
[WIP]PvP gamescript
[WIP]Rocket Express
Autofill: The torch has been pass to Nexela
Re: Comunicating data.lua and control.lua
.rk84 wrote:Could player-data.json have place for mods to write/read (via methods) scores and achievements?
Yes that would be possible.
Re: Comunicating data.lua and control.lua
*pokes even more dead thread with stick*
I could really see having a table per mod that they could save things to, which is passed into control... only simple values (no functions or anything, just string and numbers and such) I could also see a read only data.raw, if it can't be read only, it doesn't really matter too much at that point if it's edited, right? it being contained in that one control script and reset each time the game starts up... maybe a warning/error when it is changed? anyways, I'm going crazy from lack of sleep, good night.
is there a way we could pass some values or something over to our control scripts from the data scripts side? or maybe even have data.raw as a read only setup? I've seen a fair amount of mods wanting data.raw values in their control script, some hard coding those values in from their personal installs, which is horrible because a mod could change those values leading to a separation...kovarex wrote:This is nice temporary solution (if it works), but we will disable i/o operations in the lua in the future as this is huge security hole.
P.S. Tomas just made the mod dependencies, so they will be available from 0.4.
I could really see having a table per mod that they could save things to, which is passed into control... only simple values (no functions or anything, just string and numbers and such) I could also see a read only data.raw, if it can't be read only, it doesn't really matter too much at that point if it's edited, right? it being contained in that one control script and reset each time the game starts up... maybe a warning/error when it is changed? anyways, I'm going crazy from lack of sleep, good night.
Will code for Food. I also have 11+ mods!