How to build a multi-part mod?

Place to get help with not working mods / modding interface.
Post Reply
vzybilly
Fast Inserter
Fast Inserter
Posts: 143
Joined: Thu May 14, 2015 6:10 pm
Contact:

How to build a multi-part mod?

Post by vzybilly »

This might be a stupidly simple question or already answered, but I can't find it on the wiki nor the forums...

I'm wanting to make a core mod for my mod(s) and I'm not to sure on how to do it... I just started my first mod last night and completed it but now I'm ready for my next few, they all use a script and I want to make that script a core mod... but I don't know how 'separate' mods will interact, I know I can say that a mod depends on another but how can I run a lua script of the other and such?

This is kinda the dependency tree I'm wanting to make

Core Mod
  • Mod A
    Mod B
    • Mod C
      Mod D
    Mod E
A, B, E use Core. C, D use B...
Will code for Food. I also have 11+ mods!

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

Re: How to build a multi-part mod?

Post by Choumiko »

Custom events and interfaces are the only way of mods communicating with each other that i'm aware of. I'm assuming the core mod offers shared functionality/data for the others, so interfaces may be the way to go

vzybilly
Fast Inserter
Fast Inserter
Posts: 143
Joined: Thu May 14, 2015 6:10 pm
Contact:

Re: How to build a multi-part mod?

Post by vzybilly »

C and D will call a method in a script of B, passing in a thingy (class?) that uses { } as a wrapper... it holds strings, booleans, function pointers and more of the things. the interface said only primitives which would mean just the string and booleans... not the function pointers... correct?

I'm new to lua btw...
Will code for Food. I also have 11+ mods!

Rseding91
Factorio Staff
Factorio Staff
Posts: 13219
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: How to build a multi-part mod?

Post by Rseding91 »

vzybilly wrote:C and D will call a method in a script of B, passing in a thingy (class?) that uses { } as a wrapper... it holds strings, booleans, function pointers and more of the things. the interface said only primitives which would mean just the string and booleans... not the function pointers... correct?

I'm new to lua btw...
The interface will accept Lua primitives and LuaObjects (Factorio object references).
If you want to get ahold of me I'm almost always on Discord.

vzybilly
Fast Inserter
Fast Inserter
Posts: 143
Joined: Thu May 14, 2015 6:10 pm
Contact:

Re: How to build a multi-part mod?

Post by vzybilly »

Ok, I'll try to build it up when I get back home in afew hours, I'll post my results...
Will code for Food. I also have 11+ mods!

vzybilly
Fast Inserter
Fast Inserter
Posts: 143
Joined: Thu May 14, 2015 6:10 pm
Contact:

Re: How to build a multi-part mod?

Post by vzybilly »

Just an update, I'm trying out the remote interface thing, I'm currently getting

Code: Select all

attempt to index global 'remote' (a nil value)
but I think it might work after I get that settled... will update if I get things to work or can't...
Will code for Food. I also have 11+ mods!

vzybilly
Fast Inserter
Fast Inserter
Posts: 143
Joined: Thu May 14, 2015 6:10 pm
Contact:

Re: How to build a multi-part mod?

Post by vzybilly »

So, I still can't get it to work and right now my code is something like this...

MainMod/data.lua:
require("scripts.tools")
remote.addinterface("vzyCompressedAutoGen", {generate = generateMod(mod)})
SecondMod/data.lua:
remote.call("vzyCompressedAutoGen", "generateMod", require("prototypes.solar"))
And I get:
6.497 Error Util.cpp:43: __MainMod__/data.lua:2: attempt to index global 'remote' (a nil value)
Will code for Food. I also have 11+ mods!

User avatar
rk84
Filter Inserter
Filter Inserter
Posts: 556
Joined: Wed Feb 13, 2013 9:15 am
Contact:

Re: How to build a multi-part mod?

Post by rk84 »

Test mode
Searching Flashlight
[WIP]Fluid handling expansion
[WIP]PvP gamescript
[WIP]Rocket Express
Autofill: The torch has been pass to Nexela

vzybilly
Fast Inserter
Fast Inserter
Posts: 143
Joined: Thu May 14, 2015 6:10 pm
Contact:

Re: How to build a multi-part mod?

Post by vzybilly »

from what I just read, a glob isn't available till a world starts up, the data scripts being when the game starts up, I don't see how those are helpful... I'll try to play around with a glob thing...
Will code for Food. I also have 11+ mods!

vzybilly
Fast Inserter
Fast Inserter
Posts: 143
Joined: Thu May 14, 2015 6:10 pm
Contact:

Re: How to build a multi-part mod?

Post by vzybilly »

Just tested the glob thing, I think it hates me:

Code: Select all

attempt to index global 'glob' (a nil value)
I got that from

Code: Select all

glob.vzyCompressedAutoGen = generateMod
Will code for Food. I also have 11+ mods!

johanwanderer
Fast Inserter
Fast Inserter
Posts: 157
Joined: Fri Jun 26, 2015 11:13 pm

Re: How to build a multi-part mod?

Post by johanwanderer »

data.lua is strictly for static entity generation. Each data.lua file is called sequentially, in the dependency order. Therefore, you cannot call things from one data.lua to another. All you should do there is build up the data{} table for the whole game.

control.lua is where interactions between mods (the remote interface) is taken place. Because each mod (whether in whole or in part) is run in a separated instance of the Lua interpreter, you cannot call things directly. Each mod has its own "glob" table, and other mods cannot see that.

vzybilly
Fast Inserter
Fast Inserter
Posts: 143
Joined: Thu May 14, 2015 6:10 pm
Contact:

Re: How to build a multi-part mod?

Post by vzybilly »

johanwanderer wrote:data.lua is strictly for static entity generation. Each data.lua file is called sequentially, in the dependency order. Therefore, you cannot call things from one data.lua to another. All you should do there is build up the data{} table for the whole game.

control.lua is where interactions between mods (the remote interface) is taken place. Because each mod (whether in whole or in part) is run in a separated instance of the Lua interpreter, you cannot call things directly. Each mod has its own "glob" table, and other mods cannot see that.
I'm wanting to have a root mod that builds things for the other mods... you're pretty much saying that I have to copy and past the same file across all my planned mods then?
Will code for Food. I also have 11+ mods!

vzybilly
Fast Inserter
Fast Inserter
Posts: 143
Joined: Thu May 14, 2015 6:10 pm
Contact:

Re: How to build a multi-part mod?

Post by vzybilly »

I have just tried a more hacky way to make things work but

Code: Select all

7.295 Error Util.cpp:43: Key vzyCompressedAutoGen has unknown type
the Code I'm trying to get to work is:

Code: Select all

require("scripts.tools")
data.raw.item["vzyCompressedAutoGen"] = generateMod
the generateMod is a method in scripts.tools
Will code for Food. I also have 11+ mods!

johanwanderer
Fast Inserter
Fast Inserter
Posts: 157
Joined: Fri Jun 26, 2015 11:13 pm

Re: How to build a multi-part mod?

Post by johanwanderer »

As long as generateMod() return a valid item table, that should work.

User avatar
rk84
Filter Inserter
Filter Inserter
Posts: 556
Joined: Wed Feb 13, 2013 9:15 am
Contact:

Re: How to build a multi-part mod?

Post by rk84 »

vzybilly wrote:from what I just read, a glob isn't available till a world starts up, the data scripts being when the game starts up, I don't see how those are helpful... I'll try to play around with a glob thing...
vzybilly wrote:MainMod/data.lua
SecondMod/data.lua
Yup, data.lua are used when factorio is loading. Name change to control.lua perhaps? Also in my post. I did not mean glob, but global. Other words the _G -table that holds global values (e.g. in game: game, glob, remote, serpent or anything you define).
Test mode
Searching Flashlight
[WIP]Fluid handling expansion
[WIP]PvP gamescript
[WIP]Rocket Express
Autofill: The torch has been pass to Nexela

vzybilly
Fast Inserter
Fast Inserter
Posts: 143
Joined: Thu May 14, 2015 6:10 pm
Contact:

Re: How to build a multi-part mod?

Post by vzybilly »

generateMod will actually build the Items, Recipes, and Technologies for the items, as a tier system. the thing that gets passed into it is pretty much the base game thing to upgrade and how to upgrade it for different tiers, right now I'm testing solar panels and got it to work but I want to make mods for the accumulators and pretty much everything else...

is control.lua to late to add items, recipes, and tech?

is the "_G-table" something I could do at the data step? could you also give a link to what it is? I pretty much just started learning lua last night when I started this mod set...
Will code for Food. I also have 11+ mods!

User avatar
rk84
Filter Inserter
Filter Inserter
Posts: 556
Joined: Wed Feb 13, 2013 9:15 am
Contact:

Re: How to build a multi-part mod?

Post by rk84 »

vzybilly wrote: is control.lua to late to add items, recipes, and tech??
All prototypes are defined only in start, but you can use it to control what is available for player in game.
vzybilly wrote: is the "_G-table" something I could do at the data step? could you also give a link to what it is? I pretty much just started learning lua last night when I started this mod set...
Yes and you have already use it, because global variables does not require any special declaration. Now there is no remote.interfaces during loading, but there is no need. What your core mod leaves in global table, it can be used by next mod in loading.

Programming in Lua: 1.2 – Global Variables
Programming in Lua: 14 – The Environment
Test mode
Searching Flashlight
[WIP]Fluid handling expansion
[WIP]PvP gamescript
[WIP]Rocket Express
Autofill: The torch has been pass to Nexela

vzybilly
Fast Inserter
Fast Inserter
Posts: 143
Joined: Thu May 14, 2015 6:10 pm
Contact:

Re: How to build a multi-part mod?

Post by vzybilly »

rk84 wrote:
vzybilly wrote: is control.lua to late to add items, recipes, and tech??
All prototypes are defined only in start, but you can use it to control what is available for player in game.
vzybilly wrote: is the "_G-table" something I could do at the data step? could you also give a link to what it is? I pretty much just started learning lua last night when I started this mod set...
Yes and you have already use it, because global variables does not require any special declaration. Now there is no remote.interfaces during loading, but there is no need. What your core mod leaves in global table, it can be used by next mod in loading.

Programming in Lua: 1.2 – Global Variables
Programming in Lua: 14 – The Environment
Thanks for the links, I was able to get it all working on the first try~

For anyone else looking on how I did it
Core:

Code: Select all

_G.vzyCompressedAutoGen = generateMod
Secondary:

Code: Select all

_G.vzyCompressedAutoGen(require("prototypes.solar"))
I doubt it's the best way but it works for what I wanted
Will code for Food. I also have 11+ mods!

Post Reply

Return to “Modding help”