Can someone please count brackets for me? I'm serious.

Place to get help with not working mods / modding interface.
000
Burner Inserter
Burner Inserter
Posts: 11
Joined: Mon Dec 27, 2021 5:00 pm
Contact:

Can someone please count brackets for me? I'm serious.

Post by 000 »

Made a basic mod as a hasty test. In practical terms all it should do is add a new, more expensive-to-craft accumulator with a different sprite. I was expecting to test it in this current stage, and then have to ask for help with the part where I make it work as all three of its constituent parts.

However, I can't even test it. Launching Factorio gives me the error:
Failed to load mods: _ _3in1_ _/data.lua:5: '}' expected (to close '{' at line 2) near 'minable'
The word "minable" does not appear at line 2. It appears at line 5. And, as far as i can tell, there are no missed brackets. My IDE highlights closing/opening brackets and I even manually counted.

I don't normally ask for help with hunt-the-missing-punctuation but I am going insane.

If anyone is feeling so disposed, would they tell me what I'm missing?

Here are the full contents of data.lua:
data:extend({
{type = 'accumulator', name = '3in1-entity',
flags = {'placeable-neutral', 'player-creation'},
icon = sprite '3in1-item.png', icon_size = 64
minable = {mining_time = 1, result = '3in1-item'},
max_health = 150, corpse = 'small-remnants',
collision_box = {{-0.4, -0.4}, {0.4, 0.4}},
selection_box = {{-0.5, -1.3}, {0.5, 0.5}},
energy_source = {type = 'electric',
usage_priority = 'tertiary'},
vehicle_impact_sound = require("__base__/prototypes/entity/sounds")['generic_impact'],
picture = {
filename = sprite '3in1.png',
priority = 'extra-high',
width = 128,
height = 128,
shift = {0.5, -0.475},
scale = 0.5,},
circuit_wire_max_distance = default_circuit_wire_max_distance,
default_output_signal = {type='item', name='3in1'},
},

{type = 'item', name = '3in1-item',
icon = sprite '3in1-item.png', icon_size = 64,
subgroup = 'energy', order= 'z',
place_result = '3in1-entity',
stack_size = 50},

{type = 'recipe', name = '3in1-recipe',
normal = {ingredients=
{'accumulator', 1},
{'substation', 1},
{'roboport', 1}
result = '3in1-item',
energy_required = 30}},

})
FuryoftheStars
Smart Inserter
Smart Inserter
Posts: 2768
Joined: Tue Apr 25, 2017 2:01 pm
Contact:

Re: Can someone please count brackets for me? I'm serious.

Post by FuryoftheStars »

I'm on my phone... not gonna count it, sorry. :) But if you use something that does syntax highlighting, like Notepad++, that can help you out. ;)
My Mods: Classic Factorio Basic Oil Processing | Sulfur Production from Oils | Wood to Oil Processing | Infinite Resources - Normal Yield | Tree Saplings (Redux) | Alien Biomes Tweaked | Restrictions on Artificial Tiles | New Gear Girl & HR Graphics
000
Burner Inserter
Burner Inserter
Posts: 11
Joined: Mon Dec 27, 2021 5:00 pm
Contact:

Re: Can someone please count brackets for me? I'm serious.

Post by 000 »

FuryoftheStars wrote: Fri May 10, 2024 7:01 am I'm on my phone... not gonna count it, sorry. :) But if you use something that does syntax highlighting, like Notepad++, that can help you out. ;)
Unfortunately, Notepad++ is what I'm using, that's what I meant by having an IDE that highlights opening/closing brackets. If I click on a bracket in Notepad++, it shows up red, and it also highlights the other end of it (either the opener or closer as appropriate) in red. I appreciate the thought, though.
Bilka
Factorio Staff
Factorio Staff
Posts: 3309
Joined: Sat Aug 13, 2016 9:20 am
Contact:

Re: Can someone please count brackets for me? I'm serious.

Post by Bilka »

There was a comma missing at the end of the first "icon = sprite '3in1-item.png', icon_size = 64" line. And another one at the end of the "{'roboport', 1}" line.

Code: Select all

data:extend({
{type = 'accumulator', name = '3in1-entity',
flags = {'placeable-neutral', 'player-creation'},
icon = sprite '3in1-item.png', icon_size = 64,
minable = {mining_time = 1, result = '3in1-item'},
max_health = 150, corpse = 'small-remnants',
collision_box = {{-0.4, -0.4}, {0.4, 0.4}},
selection_box = {{-0.5, -1.3}, {0.5, 0.5}},
energy_source = {type = 'electric',
usage_priority = 'tertiary'},
vehicle_impact_sound = require("__base__/prototypes/entity/sounds")['generic_impact'],
picture = {
filename = sprite '3in1.png',
priority = 'extra-high',
width = 128,
height = 128,
shift = {0.5, -0.475},
scale = 0.5,},
circuit_wire_max_distance = default_circuit_wire_max_distance,
default_output_signal = {type='item', name='3in1'},
},

{type = 'item', name = '3in1-item',
icon = sprite '3in1-item.png', icon_size = 64,
subgroup = 'energy', order= 'z',
place_result = '3in1-entity',
stack_size = 50},

{type = 'recipe', name = '3in1-recipe',
normal = {ingredients=
{'accumulator', 1},
{'substation', 1},
{'roboport', 1},
result = '3in1-item',
energy_required = 30}},

})
I can recommend an editor that has language server for Lua, like VSCode does with https://marketplace.visualstudio.com/it ... umneko.lua. Its errors and highlighting can be better than Lua's built in errors, like in this case:
Screenshot_20240510_095024.png
Screenshot_20240510_095024.png (35.48 KiB) Viewed 963 times
And with FMTK you even get code completion for the Factorio Lua API.
I'm an admin over at https://wiki.factorio.com. Feel free to contact me if there's anything wrong (or right) with it.
000
Burner Inserter
Burner Inserter
Posts: 11
Joined: Mon Dec 27, 2021 5:00 pm
Contact:

Re: Can someone please count brackets for me? I'm serious.

Post by 000 »

Bilka wrote: Fri May 10, 2024 7:43 am There was a comma missing at the end of the first "icon = sprite '3in1-item.png', icon_size = 64" line. And another one at the end of the "{'roboport', 1}" line.
Thank you! I knew I was just missing it. Why is this the hardest part of debugging.

As expected, it throws other errors but I can deal with those.

Ooh, VSCode with those extensions is way better, thanks for the reccommendation! My experience with programming is mainly limited to python stuff for personal use, so VSCode has always seemed kind of excessive until now.
Tertius
Filter Inserter
Filter Inserter
Posts: 921
Joined: Fri Mar 19, 2021 5:58 pm
Contact:

Re: Can someone please count brackets for me? I'm serious.

Post by Tertius »

000 wrote: Fri May 10, 2024 7:51 am Why is this the hardest part of debugging.
Using an editor such as Vscode with integrated and immediate syntax and type check from the first word you write in a new source file avoids much hassle. These editors appear as overkill for just a small project, but they are not. They take away all this tedious searching, because you write your code correctly in the first place. Don't start using it if your project reaches some complexity but start using it right from the start. The type checking is extraordinarily great for a language like Lua that has no syntax to declare and enforce types.
FuryoftheStars
Smart Inserter
Smart Inserter
Posts: 2768
Joined: Tue Apr 25, 2017 2:01 pm
Contact:

Re: Can someone please count brackets for me? I'm serious.

Post by FuryoftheStars »

Not to take away from the suggestions of better IDEs because, yeah, that certainly can point out things like that faster, but different formatting could've very quickly shown it at least wasn't actually brackets (or at least not in the way the compiler was saying), allowing you to concentrate your efforts on looking elsewhere:
Screenshot 2024-05-10 085007.png
Screenshot 2024-05-10 085007.png (97.07 KiB) Viewed 913 times

With this, the first missing comma at least sticks out to me, but also I'm noticing that in your recipe, "ingredients" is missing both opening and closing brackets (in addition to the other comma Bilka pointed out), and that's just a quick visual inspection without even going bracket to bracket. :D
My Mods: Classic Factorio Basic Oil Processing | Sulfur Production from Oils | Wood to Oil Processing | Infinite Resources - Normal Yield | Tree Saplings (Redux) | Alien Biomes Tweaked | Restrictions on Artificial Tiles | New Gear Girl & HR Graphics
pleegwat
Filter Inserter
Filter Inserter
Posts: 278
Joined: Fri May 19, 2017 7:31 pm
Contact:

Re: Can someone please count brackets for me? I'm serious.

Post by pleegwat »

While I agree with your formatting preferences Fury, I suspect being blind to your own mistakes applies here as well.
FuryoftheStars
Smart Inserter
Smart Inserter
Posts: 2768
Joined: Tue Apr 25, 2017 2:01 pm
Contact:

Re: Can someone please count brackets for me? I'm serious.

Post by FuryoftheStars »

Oh, certainly. I've done it a number of times myself. But not having multiple items on the same line or making sure the opening and closing brackets are clearly visible to each other certainly helps.

Examples:

Code: Select all

icon = sprite '3in1-item.png', icon_size = 64

-- vs

icon = sprite '3in1-item.png',
icon_size = 64

Code: Select all

energy_source = {type = 'electric',
usage_priority = 'tertiary'},

-- vs

energy_source = {
    type = 'electric',
    usage_priority = 'tertiary'
},
My Mods: Classic Factorio Basic Oil Processing | Sulfur Production from Oils | Wood to Oil Processing | Infinite Resources - Normal Yield | Tree Saplings (Redux) | Alien Biomes Tweaked | Restrictions on Artificial Tiles | New Gear Girl & HR Graphics
SoShootMe
Filter Inserter
Filter Inserter
Posts: 517
Joined: Mon Aug 03, 2020 4:16 pm
Contact:

Re: Can someone please count brackets for me? I'm serious.

Post by SoShootMe »

FuryoftheStars wrote: Fri May 10, 2024 7:46 pm Oh, certainly. I've done it a number of times myself. But not having multiple items on the same line or making sure the opening and closing brackets are clearly visible to each other certainly helps.
I'm sure everyone has been there :). For languages that allow it (such as Lua, at least in the case of tables), as well as one-item-per-line it can be useful to always have a separator at the end of the line. Although I have frequently seen this grammar feature described as being intended to simplify machine-generating code, I think it's also useful for hand-written code, especially if you need to reorder things. And as a bonus it yields nicer diffs (and better blame).
pleegwat
Filter Inserter
Filter Inserter
Posts: 278
Joined: Fri May 19, 2017 7:31 pm
Contact:

Re: Can someone please count brackets for me? I'm serious.

Post by pleegwat »

I even recall having had to write extra code in a parser to reject trailing commas in array definitions.
Post Reply

Return to “Modding help”