[solved] [0.17.43] basegame item edit - change armor grid module slot size

Place to get help with not working mods / modding interface.
AlFara
Burner Inserter
Burner Inserter
Posts: 16
Joined: Sat May 25, 2019 4:14 pm
Contact:

[solved] [0.17.43] basegame item edit - change armor grid module slot size

Post by AlFara »

as stated in the title, i'm looking for a way to modify the slot size of an armor module;
more precisely, the exoskeleton shall be overwritten to change it's grid size from 2x4 to 6x6

folder state:
base->folder->prototypes->item->equipment.lua (protptypes->equipment folder doesn't work either)
equipment.lua (with a bit of overkill):

Code: Select all

data.raw.equipment["exoskeleton-equipment"].shape.width = 6,
data.raw.equipment["exoskeleton-equipment"].shape.height = 6,
data.raw.item["exoskeleton-equipment"].shape.width = 6,
data.raw.item["exoskeleton-equipment"].shape.height = 6
base exoskeleton is found in the game files at
Factorio->data->base->prototypes->equipment->equipment.lua
and looks like:

Code: Select all

{
    type = "movement-bonus-equipment",
    name = "exoskeleton-equipment",
    sprite =
    {
      filename = "__base__/graphics/equipment/exoskeleton-equipment.png",
      width = 64,
      height = 128,
      priority = "medium"
    },
    shape =
    {
      width = 2,
      height = 4,
      type = "full"
    },
    energy_source =
    {
      type = "electric",
      usage_priority = "secondary-input"
    },
    energy_consumption = "200kW",
    movement_bonus = 0.3,
    categories = {"armor"}
  }
for testing purposes, i even threw my files into an existing (and working) mod (just to make sure) and it's not working either.
anyone got an idea why it's not working?
Last edited by AlFara on Tue May 28, 2019 2:28 pm, edited 1 time in total.
User avatar
darkfrei
Smart Inserter
Smart Inserter
Posts: 2905
Joined: Thu Nov 20, 2014 11:11 pm
Contact:

Re: [0.17.43] basegame item edit - change armor grid module slot size

Post by darkfrei »

AlFara wrote: Tue May 28, 2019 6:33 am as stated in the title, i'm looking for a way to modify the slot size of an armor module;
more precisely, the exoskeleton shall be overwritten to change it's grid size from 2x4 to 6x6

folder state:
base->folder->prototypes->item->equipment.lua (protptypes->equipment folder doesn't work either)
equipment.lua (with a bit of overkill):

Code: Select all

data.raw.equipment["exoskeleton-equipment"].shape.width = 6,
data.raw.equipment["exoskeleton-equipment"].shape.height = 6,
data.raw.item["exoskeleton-equipment"].shape.width = 6,
data.raw.item["exoskeleton-equipment"].shape.height = 6
Please find the mod for modding
viewtopic.php?f=135&t=45107
You can find all prototypes without your mod, then set up some parameters and insert in your mod just as
prototype.shape = {width=6, height=6}
Note that you need to place it in your armor again, migration makes no change. Add some log ('my code works') to be sure that your code was read. You must save the file to data.lua as UTF-8 without BOM.
eduran
Filter Inserter
Filter Inserter
Posts: 344
Joined: Fri May 09, 2014 2:52 pm
Contact:

Re: [0.17.43] basegame item edit - change armor grid module slot size

Post by eduran »

Setting the shape for the item does not do anything. Only the equipment prototype has a shape property:

Code: Select all

data.raw["movement-bonus-equipment"]["exoskeleton-equipment"].shape.width = 6
data.raw["movement-bonus-equipment"]["exoskeleton-equipment"].shape.height = 6
The fact that your code did not throw a "trying-to-index-nil-value" error tells me it did not even run. Since you did not put it into data.lua directly, did you actually require it there?
User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5211
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: [0.17.43] basegame item edit - change armor grid module slot size

Post by eradicator »

darkfrei wrote: Tue May 28, 2019 7:03 am You must save the file to data.lua as UTF-8 without BOM.
UTF8 files with BOM work just fine. And for anything but info.json the engine should throw an error if it doesn't like the encoding.
AlFara wrote: Tue May 28, 2019 6:33 am
base->folder->prototypes->item->equipment.lua (protptypes->equipment folder doesn't work either)
equipment.lua (with a bit of overkill):
Are you just replicating the base game folder structure in a mod? The structure is irrelevant. Only require() is important.
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.
AlFara
Burner Inserter
Burner Inserter
Posts: 16
Joined: Sat May 25, 2019 4:14 pm
Contact:

Re: [0.17.43] basegame item edit - change armor grid module slot size

Post by AlFara »

darkfrei's mod put out the following lines:
data.raw["movement-bonus-equipment"]["exoskeleton-equipment"].shape.width = 2
data.raw["movement-bonus-equipment"]["exoskeleton-equipment"].shape.height = 4

putting the modified versions (which look like eduran posted) into the data.lua worked just fine

thanks@all

"Only require() is important"
okay, got it.

@eduran: as i've mentioned, i even took another mod and put the files in there for testing purposes (was one of bobs). the mod started like regular, did not throw an error and it didn't change the grid size at all. if i put the wrong lines into the data lua, it throws an error as you already said.
"did you actually require it there" i took one of bobs mods, checked where he changed stuff from exoskeletons and tried to do a similar thing to get it running.
eduran
Filter Inserter
Filter Inserter
Posts: 344
Joined: Fri May 09, 2014 2:52 pm
Contact:

Re: [solved] [0.17.43] basegame item edit - change armor grid module slot size

Post by eduran »

Only data.lua / data-updates.lua / data-final-fixes.lua run automatically during the data stage. To run any other file (like your equipment.lua), you need to tell Factorio's Lua engine to run it. That is done with

Code: Select all

-- in data.lua
-- assuming you have equipment.lua in /my_mod_x.y.z/prototypes/
require "prototypes.equipment"  -- no .lua at the end
Just copying your file into an existing mod does not run that file. By adding the code directly to data.lua you don't need require().
User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5211
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: [solved] [0.17.43] basegame item edit - change armor grid module slot size

Post by eradicator »

eduran wrote: Tue May 28, 2019 2:39 pm

Code: Select all

require "prototypes.equipment"  -- no .lua at the end
Just a correction for the future reader: require() is a just a function, and has a somewhat variable argument structure. The "." is just a possible directory donator. You could just as well do

Code: Select all

require("__my-mod-name__/path/to/my/file.lua")
@OP:
Btw if you look at /factorio/data/base/data.lua you'll see that the base mod does huge blocks of require() too, no magic there.
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.
User avatar
darkfrei
Smart Inserter
Smart Inserter
Posts: 2905
Joined: Thu Nov 20, 2014 11:11 pm
Contact:

Re: [0.17.43] basegame item edit - change armor grid module slot size

Post by darkfrei »

AlFara wrote: Tue May 28, 2019 2:28 pm darkfrei's mod put out the following lines:
data.raw["movement-bonus-equipment"]["exoskeleton-equipment"].shape.width = 2
data.raw["movement-bonus-equipment"]["exoskeleton-equipment"].shape.height = 4
It's the same as
data.raw["movement-bonus-equipment"]["exoskeleton-equipment"].shape={width = 2, height = 4}
eduran
Filter Inserter
Filter Inserter
Posts: 344
Joined: Fri May 09, 2014 2:52 pm
Contact:

Re: [solved] [0.17.43] basegame item edit - change armor grid module slot size

Post by eduran »

darkfrei wrote: Tue May 28, 2019 3:19 pm It's the same as
data.raw["movement-bonus-equipment"]["exoskeleton-equipment"].shape={width = 2, height = 4}
Yes, in this case. But your version will set all other properties stored in 'shape' to nil, while mine leaves them intact. It is safer to just overwrite the properties you want to change instead of replacing the entire table.
AlFara
Burner Inserter
Burner Inserter
Posts: 16
Joined: Sat May 25, 2019 4:14 pm
Contact:

Re: [solved] [0.17.43] basegame item edit - change armor grid module slot size

Post by AlFara »

thanks for the tutorial on require and data.lua, i didn't use that before in any way. I'll probably stick to data.lua for now unless i need to add a lot of stuff.

about the "...shape={width = 2, height = 4}" stuff, is there a way to write it in one line while overwriting the listed elements only? e.g. with a flag or sth.
User avatar
Deadlock989
Smart Inserter
Smart Inserter
Posts: 2529
Joined: Fri Nov 06, 2015 7:41 pm

Re: [solved] [0.17.43] basegame item edit - change armor grid module slot size

Post by Deadlock989 »

AlFara wrote: Tue May 28, 2019 5:11 pm about the "...shape={width = 2, height = 4}" stuff, is there a way to write it in one line while overwriting the listed elements only? e.g. with a flag or sth.

Code: Select all

data.raw["movement-bonus-equipment"]["exoskeleton-equipment"].shape = {width = 2, height = 4, type = "full"}
The EquipmentShape prototype doesn't have any other parameters that are actually used by the game so this covers all the bases.

https://wiki.factorio.com/Types/EquipmentShape
Post Reply

Return to “Modding help”