[Fixed] Adding data: to game

Place to get help with not working mods / modding interface.
Post Reply
Rafiz
Inserter
Inserter
Posts: 31
Joined: Sun Jan 17, 2021 9:28 am
Contact:

[Fixed] Adding data: to game

Post by Rafiz »

There's part of code in my mod : https://pastebin.com/8j7sGeA4 (whole file : https://pastebin.com/Sw9V7nzk)

In this part of code I define technology and add it to game. But it is nowhere to be found, I just ... don't have it in game.
Here's log from game : https://pastebin.com/cWfQiLjR my mod loads (0.741), have no errors, it is enabled... I don't understand what is failing here.

What am I doing wrong? I'm pretty sure this exact mod worked, but I worked on it like half year ago, so few new versions of game came out.

I changed value of property : order = ~~~ to some other, so it is not exactly same as in vanilla techs, but it did nothing, I have no ideas on what can I try to do.
Last edited by Rafiz on Thu Dec 30, 2021 1:11 pm, edited 3 times in total.

Rafiz
Inserter
Inserter
Posts: 31
Joined: Sun Jan 17, 2021 9:28 am
Contact:

Re: Adding technology to game

Post by Rafiz »

Typo!
data:extend(
{
recile_lube,
should be recipe_lube.
That's strange that nothing crashed. I guess data:extend just accepts nil and ends adding elements from table once it gots to nil. I would rather expect it to ... if not crash everything, then at least continue checking next elements.
Data:extend shouldn't be looping past array, until value under current index returns nil (IMO). It should rather just check # of elements in array and iterate over # elements. Maybe it does that, I don't know. It just looks as if it was "end-of-array being nil" based.

robot256
Filter Inserter
Filter Inserter
Posts: 596
Joined: Sun Mar 17, 2019 1:52 am
Contact:

Re: [Fixed] Adding data: to game

Post by robot256 »

In Lua, nil entries in a table/array are simply not stored at all.

a=nil
tab={a}

Is the same as

tab={nil}

Is the same as

tab={}

In all cases #tab=0

The only time it matters is array spacing:

tab={nil,nil,nil,42}

Is the same as

tab={[4]=42}

And #tab=4 but table_size(tab)=1 (iirc)

FuryoftheStars
Smart Inserter
Smart Inserter
Posts: 2530
Joined: Tue Apr 25, 2017 2:01 pm
Contact:

Re: [Fixed] Adding data: to game

Post by FuryoftheStars »

robot256 wrote:
Fri Dec 31, 2021 3:04 am
Well, that’s the thing the OP was confused about in their 2nd post.

If I’m following that post correctly, they were essentially entering this:
data:extend({nil, dat2, dat3, …})
And the game wasn’t inputting any of it.
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

User avatar
Silari
Filter Inserter
Filter Inserter
Posts: 489
Joined: Sat Jan 27, 2018 10:04 pm
Contact:

Re: [Fixed] Adding data: to game

Post by Silari »

Probably because of how array's are handled in LUA and where certain functions consider their end to be.
LUA documentation wrote:The basic Lua library provides ipairs, a handy function that allows you to iterate over the elements of an array, following the convention that the array ends at its first nil element.
So in this case, data:extend expects an array, finds the first entry to be nil, and thus treats the array as if it were empty. data:extend uses ipairs to iterate the data given to it, per the code at https://github.com/wube/factorio-data/b ... loader.lua . There's also a check that the table isn't empty, but since that uses the # operator I believe it's missing this case - the table isn't empty, it's just not being fully iterated over.

Post Reply

Return to “Modding help”